You are here

function name_field_formatter_settings_summary in Name Field 7

Implements hook_field_formatter_settings_summary().

File

./name.module, line 1351
Defines an API for displaying and inputing names.

Code

function name_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $summary = array();
  $machine_name = isset($settings['format']) ? $settings['format'] : 'default';
  if ($machine_name == 'default') {
    $summary[] = t('Format: Default');
  }
  else {
    $info = db_select('name_custom_format', 'n')
      ->fields('n')
      ->condition('machine_name', $machine_name)
      ->execute()
      ->fetchObject();
    if ($info) {
      $summary[] = t('Format: %format (@machine_name)', array(
        '%format' => $info->name,
        '@machine_name' => $info->machine_name,
      ));
    }
    else {
      $summary[] = t('Format: <strong>Missing format.</strong><br/>This field will be displayed using the Default format.');
      $machine_name = 'default';
    }
  }

  // Provide an example of the selected format.
  module_load_include('admin.inc', 'name');
  $used_components = array_filter($field['settings']['components']);
  $excluded_components = array_diff_key($used_components, _name_translations());
  $examples = name_example_names($excluded_components, $field['field_name']);
  if ($examples && ($example = array_shift($examples))) {
    $format = name_get_format_by_machine_name($machine_name);
    $formatted = check_plain(name_format($example, $format));
    if (empty($formatted)) {
      $formatted = '<em>&lt;&lt;empty&gt;&gt;</em>';
    }
    $summary[] = t('Example: !example', array(
      '!example' => $formatted,
    ));
  }
  $summary[] = t('Markup: @yesno', array(
    '@yesno' => empty($settings['markup']) ? t('no') : t('yes'),
  ));
  $output_options = _name_formatter_output_options();
  $output = empty($settings['output']) ? 'default' : $settings['output'];
  $summary[] = t('Output: @format', array(
    '@format' => $output_options[$output],
  ));
  return implode('<br/>', $summary);
}