You are here

function name_list_custom_formats in Name Field 6

Same name and namespace in other branches
  1. 7 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
Implementation of hook_menu().

File

./name.admin.inc, line 45
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 = array(
    1 => array(
      'title' => 'Mr',
      'given' => 'Joe',
      'middle' => 'John Peter Mark',
      'family' => 'Doe',
      'generational' => 'Jnr.',
      'credentials' => 'B.Sc., Ph.D.',
    ),
    2 => array(
      'title' => '',
      'given' => 'JOAN',
      'middle' => 'SUE',
      'family' => 'DOE',
      'generational' => '',
      'credentials' => '',
    ),
    3 => array(
      'title' => '',
      'given' => 'Prince',
      'middle' => '',
      'family' => '',
      'generational' => '',
      'credentials' => '',
    ),
  );
  $default_format = array(
    'ncfid' => 0,
    'name' => t('Default'),
    'machine_name' => 'default',
    '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/settings/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/settings/name/' . $ncfid);
      $links[] = l(t('Delete'), 'admin/settings/name/' . $ncfid . '/delete');
      $row[] = implode('&nbsp;&nbsp;&nbsp;&nbsp;', $links);
    }
    else {
      $row[] = '';
    }
    $rows[] = $row;
  }
  $help = '<p><strong>' . t('The three examples are for the following users:') . '</strong><p>';
  $help_items = array();
  foreach ($example_names as $example_name) {
    $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 are "%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>>',
    ));
  }
  $fieldset = _name_get_name_format_help_form();
  $output = theme('table', $header, $rows) . $help . theme('item_list', $help_items, NULL, 'ol') . drupal_render($fieldset);
  return $output;
}