Centarro: Customizing Inline Entity Form’s Complex Widget

Inline Entity Form is a popular Drupal module that lets you create multiple types of content (or other related entities) from a single form. We originally created the module for Drupal 7 to improve the store administrator experience in our popular Commerce Kickstart distribution. We made it a core dependency for Commerce 2.x on Drupal 8, and today it is primarily used to let you manage order items from the order add / edit form.

I subscribe to the commerce tag on Drupal Answers to give fast advice to folks when I can, and every now and then a question intrigues me enough that I can’t help but research it fully and share the results. Last week, that happened when someone asked how to add a new column to the table of order items shown on the order edit form. Since it’s a table, they expected to be able to edit a View to make it work, but Inline Entity Form’s “complex widget” used there is far too complex (hey, it’s in the name! ; ) for Views to be of use.

The default order items table on an order edit form.
The default order items table on an order edit form.

The field widget defined by the Inline Entity Form module can be added to any Entity Reference field, itself another powerful module born out of Drupal Commerce. On the edit form, it lists all of the entities referenced by the field in a table, and operations buttons in each row let you edit or remove the referenced entities. The columns in this table are defined by an inline form handler for the referenced entity type. Inline Entity Form defines a generic handler, but modules can provide custom handlers for their entity types, as Commerce Order does for the order item entity type.

Read more