You are here

function name_list_custom_formats in Name Field 7

Same name and namespace in other branches
  1. 6 name.admin.inc \name_list_custom_formats()

Lists the known custom formats.

1 string reference to 'name_list_custom_formats'
name_menu in ./name.module
Implements hook_menu().

File

./name.admin.inc, line 229
General administration functions.

Code

function name_list_custom_formats() {
  $header = array(
    t('Name'),
    t('System code'),
    t('Format'),
    t('Examples'),
    t('Actions'),
  );
  $rows = array();
  $example_names = name_example_names();
  $default_format = new stdClass();
  $default_format->ncfid = 0;
  $default_format->name = t('Default');
  $default_format->machine_name = 'default';
  $default_format->format = name_settings('default_format');
  $custom_formats = array(
    '0' => $default_format,
  ) + name_get_custom_formats();
  foreach ($custom_formats as $ncfid => $tag) {
    $row = array();
    $row[] = l($tag->name, 'admin/config/content/name/' . ($ncfid ? $ncfid : 'settings'));
    $row[] = $tag->machine_name;
    $row[] = check_plain($tag->format);
    $examples = array();
    foreach ($example_names as $index => $example_name) {
      $formatted = check_plain(name_format($example_name, $tag->format));
      if (empty($formatted)) {
        $formatted = '<em>&lt;&lt;empty&gt;&gt;</em>';
      }
      $examples[] = $formatted . " <sup>{$index}</sup>";
    }
    $row[] = implode('<br/>', $examples);
    if ($ncfid) {
      $links = array();
      $links[] = l(t('Edit'), 'admin/config/content/name/' . $ncfid);
      $links[] = l(t('Delete'), 'admin/config/content/name/' . $ncfid . '/delete');
      $row[] = implode('&nbsp;&nbsp;&nbsp;&nbsp;', $links);
    }
    else {
      $row[] = l(t('Edit'), 'admin/config/content/name/settings');
    }
    $rows[] = array(
      'data' => $row,
      'id' => 'name-' . $ncfid,
    );
  }
  $help = '<p><strong>' . t('The three examples are for the following users:') . '</strong><p>';
  $help_items = array();
  foreach ($example_names as $example_name) {

    // @todo make the labels generic.
    $help_items[] = t('The example %user has the following components; title is "%title", given is "%given", middle is "%middle", family is "%family", generational is "%generational", credentials is "%credentials"', array(
      '%user' => name_format($example_name, 't+ g+ m+ f+ s+ c'),
      '%title' => $example_name['title'] ? $example_name['title'] : '<<empty>>',
      '%given' => $example_name['given'] ? $example_name['given'] : '<<empty>>',
      '%middle' => $example_name['middle'] ? $example_name['middle'] : '<<empty>>',
      '%family' => $example_name['family'] ? $example_name['family'] : '<<empty>>',
      '%generational' => $example_name['generational'] ? $example_name['generational'] : '<<empty>>',
      '%credentials' => $example_name['credentials'] ? $example_name['credentials'] : '<<empty>>',
    ));
  }

  // A workaround to display a collapable fieldset inside a standard page.
  // Revisit and remove this once the issue is sorted.
  $form_state = array();
  $fieldset = _name_get_name_format_help_form();
  $fieldset = form_process_fieldset($fieldset, $form_state);
  return array(
    'table' => array(
      '#markup' => theme('table', array(
        'header' => $header,
        'rows' => $rows,
      )) . $help . theme('item_list', array(
        'items' => $help_items,
        'type' => 'ol',
      )),
    ),
    'name_format_help' => $fieldset,
  );
}