Drupal - How to show fields in the Inline Entity Form display widget?

Use hook_inline_entity_form_table_fields_alter() this is what I am using on a current site:

function MY_MODULE_inline_entity_form_table_fields_alter(&$fields, $context) {
  //Determine the bundle and entity type from $context

  unset($fields['id']); //<get rid of the id field

  //add any fields you need to the $fields array
  $fields['FIELD_NAME'] = array(
    'type' => 'field',
    'label' => t('FIELD'),
    'weight' => 2
  );

}

To add to Mojeferous' answer, you do this indeed by implementing hook_inline_entity_form_table_fields_alter() in your module which is documented in the modules' inline_entity_form.api.php.

You can add properties, custom fields or call backs as columns. See the below example.

Note: to prevent error messages, check for the entity types.

function custommodule_inline_entity_form_table_fields_alter(&$fields, $context) {
  if ($context['parent_entity_type'] == 'customentity' && $context['entity_type'] == 'anothercustomentity') {
    $fields['field_custom'] = array(
      'type' => 'field',
      'label' => t('Custom'),
      'weight' => 101,
    );
    $fields['title'] = array(
      'type' => 'property',
      'label' => t('Title'),
      'weight' => 1,
    );
  }
}

See: https://www.drupal.org/node/2091585 and https://www.drupal.org/node/2497289


I made a module - IEF Table View Mode that can help you with that using the view mode

This module defines a view mode to set up the columns of the table for the Inline Entity Form widget.

With this you could define which fields (with their settings) and in what order will be displayed in the table. Also includes the properties defined by the entity and IEF.

Tags:

Entities