7.x field_ui.api.php hook_field_formatter_settings_summary($field, $instance, $view_mode)

Return a short summary for the current formatter settings of an instance.

If an empty result is returned, the formatter is assumed to have no configurable settings, and no UI will be provided to display a settings form.

Parameters

$field: The field structure.

$instance: The instance structure.

$view_mode: The view mode for which a settings summary is requested.

Return value

A string containing a short summary of the formatter settings.

Related topics

4 functions implement hook_field_formatter_settings_summary()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_field_formatter_settings_summary in modules/field/tests/field_test.field.inc
Implements hook_field_formatter_settings_summary().
image_field_formatter_settings_summary in modules/image/image.field.inc
Implements hook_field_formatter_settings_summary().
number_field_formatter_settings_summary in modules/field/modules/number/number.module
Implements hook_field_formatter_settings_summary().
text_field_formatter_settings_summary in modules/field/modules/text/text.module
Implements hook_field_formatter_settings_summary().
1 invocation of hook_field_formatter_settings_summary()
field_ui_display_overview_form in modules/field_ui/field_ui.admin.inc
Form constructor for the field display settings for a given view mode.

File

modules/field_ui/field_ui.api.php, line 192
Hooks provided by the Field UI module.

Code

function hook_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  $summary = '';

  if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') {
    $summary = t('Length: @chars chars', array('@chars' => $settings['trim_length']));
  }

  return $summary;
}

Comments

rszrama’s picture

This is not a true hook in the sense that it will ever be generically invoked allowing any module to build the display formatter's summary. It actually functions more like a module callback that is directly invoked by field_ui_display_overview_form() in field_ui.admin.inc.

That function loops over every field on an entity and looks for a summary callback from the module defining the field's display formatter to determine if it should be called to add to the display overview form. This means your implementation of this hook need not wonder if it is going to be called for some unrelated display formatter except by intentional developer effort via hook_field_formatter_info_alter().