diff --git a/includes/entity.inline_entity_form.inc b/includes/entity.inline_entity_form.inc index 7b3891d..e8f00d5 100644 --- a/includes/entity.inline_entity_form.inc +++ b/includes/entity.inline_entity_form.inc @@ -89,6 +89,9 @@ class EntityInlineEntityFormController { * - formatter: The formatter used to display the field, or "hidden". * - settings: An array passed to the formatter. If empty, defaults are used. * - delta: If provided, limits the field to just the specified delta. + * Special keys for type 'property', both optional: + * - formatter callback: A formatter callback used to display a property. + * - formatter arguments: Extra arguments to pass to the formatter callback. */ public function tableFields($bundles) { $info = entity_get_info($this->entityType); diff --git a/inline_entity_form.api.php b/inline_entity_form.api.php index 2401407..5df63aa 100644 --- a/inline_entity_form.api.php +++ b/inline_entity_form.api.php @@ -68,13 +68,15 @@ function hook_inline_entity_form_settings_alter(&$settings, $field, $instance) { * - type: either 'property' or 'field' to specify how the data is defined on * the related entity. * - label: the title of the table field's column in the IEF table. - * - sanitized: for 'property' type table fields, a boolean indicating whether - * or not the data has already been sanitized for output; if not present or - * FALSE, theme_inline_entity_form_entity_table() will sanitize the data for - * output using check_plain(). - * - formatter: for 'field' type table fields, the machine-name of the display - * formatter to use to render the field data. - * - weight: the sort order of the column in the IEF table. + * - weight: The position of the field relative to other fields. + * Special keys for type 'field', all optional: + * - formatter: The formatter used to display the field, or "hidden". + * - settings: An array passed to the formatter. If empty, defaults are used. + * - delta: If provided, limits the field to just the specified delta. + * Special keys for type 'property', all optional: + * - formatter callback: A formatter callback used to display a property. + * - formatter arguments: Extra arguments to pass to the formatter callback. + * * @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 70935fb..cf4b939 100644 --- a/inline_entity_form.module +++ b/inline_entity_form.module @@ -1655,9 +1655,26 @@ function theme_inline_entity_form_entity_table($variables) { $data = ''; if ($field['type'] == 'property') { $property = $wrapper->{$field_name}; - // label() returns human-readable versions of token and list properties. - $data = $property->label() ? $property->label() : $property->value(); - $data = empty($field['sanitized']) ? check_plain($data) : $data; + // Handle formatter callbacks for properties. + if (isset($field['formatter callback']) && is_callable($field['formatter callback'])) { + $arguments = array($property->value()); + // If the 'formatter arguments' key is defined, the property value + // will be the first argument to the formatter, while the other + // arguments will be appended. + if (isset($field['formatter arguments']) && is_array($field['formatter arguments'])) { + $arguments = array_merge($arguments, $field['formatter arguments']); + } + $data = call_user_func_array($field['formatter callback'], $arguments); + } + else { + // There's no formatter callback. The $property->label() method + // returns human-readable versions for properties that have an + // 'options list'. + $data = $property->label(); + if (!$data) { + $data = $property->value(array('sanitize' => TRUE)); + } + } } elseif ($field['type'] == 'field' && isset($entity->{$field_name})) { $display = array(