diff --git a/inline_entity_form.api.php b/inline_entity_form.api.php index 6e6f5bc..4dcda4a 100644 --- a/inline_entity_form.api.php +++ b/inline_entity_form.api.php @@ -59,11 +59,18 @@ function hook_inline_entity_form_settings_alter(&$settings, $field, $instance) { /** * Alter the fields used to represent an entity in the IEF table. * - * The fields can be either Field API fields or properties defined through - * hook_entity_property_info(). - * * @param $fields - * The fields to alter. + * The table fields to alter. Each field is represented by an associative + * array containing the following keys: + * - type: either 'field' or 'callback' to specify how the data is defined on + * the related entity. + * - label: the title of the table field's column in the IEF table. + * - weight: the sort order of the column in the IEF table. + * - callback: for 'callback' type table fields, a callable that returns a + * renderable array. + * - callback_arguments: (optional) an array of additional arguments to pass + * to the callback. The entity and the theme variables are always passed as + * the first two arguments. * @param $context * An array with the following keys: * - parent_entity_type: The type of the parent entity. diff --git a/inline_entity_form.module b/inline_entity_form.module index b22c9ff..bfd541e 100644 --- a/inline_entity_form.module +++ b/inline_entity_form.module @@ -482,9 +482,22 @@ function theme_inline_entity_form_entity_table($variables) { // Add fields that represent the entity. foreach ($fields as $field_name => $field) { $data = ''; - if ($entity->hasField($field_name)) { + if (($field['type'] == 'field') && $entity->hasField($field_name)) { $data = $entity->get($field_name)->getString(); } + elseif ($field['type'] == 'callback') { + $arguments = array( + 'entity' => $entity, + 'variables' => $variables, + ); + + if (isset($field['callback_arguments'])) { + $arguments = array_merge($arguments, $field['callback_arguments']); + } + + $data = call_user_func_array($field['callback'], $arguments); + } + $cells[] = array('data' => $data, 'class' => array('inline-entity-form-' . $entity_type . '-' . $field_name)); } diff --git a/src/InlineEntityForm/EntityInlineEntityFormHandler.php b/src/InlineEntityForm/EntityInlineEntityFormHandler.php index 8c39aff..e738a17 100644 --- a/src/InlineEntityForm/EntityInlineEntityFormHandler.php +++ b/src/InlineEntityForm/EntityInlineEntityFormHandler.php @@ -105,7 +105,7 @@ class EntityInlineEntityFormHandler implements InlineEntityFormHandlerInterface if ($info->hasKey('label')) { $label_key = $info->getKey('label'); $fields[$label_key] = array( - 'type' => 'property', + 'type' => 'field', 'label' => $metadata ? $metadata[$label_key]['label'] : t('Label'), 'weight' => 1, ); @@ -113,7 +113,7 @@ class EntityInlineEntityFormHandler implements InlineEntityFormHandlerInterface else { $id_key = $info->getKey('id'); $fields[$id_key] = array( - 'type' => 'property', + 'type' => 'field', 'label' => $metadata ? $metadata[$id_key]['label'] : t('ID'), 'weight' => 1, ); @@ -121,7 +121,7 @@ class EntityInlineEntityFormHandler implements InlineEntityFormHandlerInterface if (count($bundles) > 1) { $bundle_key = $info->getKey('bundle'); $fields[$bundle_key] = array( - 'type' => 'property', + 'type' => 'field', 'label' => $metadata ? $metadata[$bundle_key]['label'] : t('Type'), 'weight' => 2, ); diff --git a/src/InlineEntityForm/NodeInlineEntityFormHandler.php b/src/InlineEntityForm/NodeInlineEntityFormHandler.php index efc1b27..c0ab32f 100644 --- a/src/InlineEntityForm/NodeInlineEntityFormHandler.php +++ b/src/InlineEntityForm/NodeInlineEntityFormHandler.php @@ -28,7 +28,7 @@ class NodeInlineEntityFormHandler extends EntityInlineEntityFormHandler { public function tableFields($bundles) { $fields = parent::tableFields($bundles); $fields['status'] = [ - 'type' => 'property', + 'type' => 'field', 'label' => t('Status'), 'weight' => 100, ];