You are here

function _name_field_settings_pre_render in Name Field 7

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

Themes the global field settings of the name component into a nice table, rather than a long list of individual elements.

1 call to _name_field_settings_pre_render()
name_field_settings_pre_render in ./name.module
A #pre_render function callback for formatting field settings.

File

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

Code

function _name_field_settings_pre_render($form) {

  // $warning = t('<strong>Warning! Changing this setting after data has been created could result in the loss of data!</strong>');
  $extra_max_info = '<div>' . t('This can not be less than the longest value in the database. The minimum values are:') . '</div>';
  $extra_max_items = array();
  foreach (_name_translations() as $key => $title) {
    $extra_max_items[] = t('!title is !size', array(
      '!title' => $title,
      '!size' => $form['max_length'][$key]['#min_size'],
    ));
  }
  $extra_max_info .= theme('item_list', array(
    'items' => $extra_max_items,
  ));
  $form['field_properties'] = array(
    '#prefix' => '<table>',
    '#suffix' => '</table>',
    '#weight' => 1,
    'thead' => array(
      '#prefix' => '<thead><tr><th>' . t('Field') . '</th>',
      '#suffix' => '</tr></thead>',
      '#weight' => 0,
    ),
    'tbody' => array(
      '#prefix' => '<tbody>',
      '#suffix' => '</tbody>',
      '#weight' => 1,
      'components' => array(
        '#prefix' => '<tr><td><strong>' . t('Components') . '<sup>1</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 1,
      ),
      'minimum_components' => array(
        '#prefix' => '<tr><td><strong>' . t('Minimum components') . '<sup>2</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 2,
      ),
      'allow_family_or_given' => array(
        '#prefix' => '<tr><td>&nbsp;</td><td colspan="6">',
        '#suffix' => '</td></tr>',
        '#weight' => 2.1,
      ),
      'max_length' => array(
        '#prefix' => '<tr><td><strong>' . t('Maximum length') . '<sup>3</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 3,
      ),
      'labels' => array(
        '#prefix' => '<tr><td><strong>' . t('Labels') . '<sup>4</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 4,
      ),
      'sort_options' => array(
        '#prefix' => '<tr><td><strong>' . t('Sort options') . '<sup>5</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 5,
      ),
      'autocomplete_source' => array(
        '#prefix' => '<tr><td><strong>' . t('Autocomplete sources') . '<sup>6</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 6,
      ),
      'autocomplete_separator' => array(
        '#prefix' => '<tr><td><strong>' . t('Autocomplete separator') . '<sup>7</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 7,
      ),
    ),
    'tfoot' => array(
      '#markup' => '<tfoot><tr><td colspan="7"><ol>' . '<li>' . t('Only selected components will be activated on this field. All non-selected components / component settings will be ignored.') . '</li>' . '<li>' . t('The minimal set of components required before the field is considered completed enough to save.') . '</li>' . '<li>' . t('The maximum length of the field in characters. This must be between 1 and 255.') . $extra_max_info . '</li>' . '<li>' . t('The labels are used to distinguish the fields.') . '</li>' . '<li>' . t('This enables sorting on the options after the vocabulary terms are added and duplicate values are removed.') . '</li>' . '<li>' . t('At least one value must be selected before you can enable the autocomplete option on the input textfields.') . '<li>' . t('This allows you to override the default handling that the autocomplete uses to handle separations between components. If empty, this defaults to a single space.') . '</ol></td></tr></tfoot>',
      '#weight' => 2,
    ),
  );
  $form['field_properties']['tbody']['allow_family_or_given']['checkbox'] = $form['allow_family_or_given'];
  unset($form['allow_family_or_given']);
  $i = 0;
  foreach (_name_translations() as $key => $title) {

    // Adds the table header for the particullar field.
    $form['field_properties']['thead'][$key]['#markup'] = '<th>' . $title . '</th>';
    $form['field_properties']['thead'][$key]['#weight'] = ++$i;

    // Strip the title & description.
    unset($form['components'][$key]['#description']);
    unset($form['components'][$key]['#title']);
    unset($form['minimum_components'][$key]['#description']);
    unset($form['minimum_components'][$key]['#title']);
    unset($form['max_length'][$key]['#description']);
    unset($form['max_length'][$key]['#title']);
    $form['max_length'][$key]['#size'] = 10;
    unset($form['labels'][$key]['#description']);
    unset($form['labels'][$key]['#title']);
    $form['labels'][$key]['#size'] = 10;
    if (isset($form['sort_options'][$key])) {
      unset($form['sort_options'][$key]['#description']);
      unset($form['sort_options'][$key]['#title']);
    }
    unset($form['autocomplete_source'][$key]['#description']);
    unset($form['autocomplete_source'][$key]['#title']);
    unset($form['autocomplete_separator'][$key]['#description']);
    unset($form['autocomplete_separator'][$key]['#title']);

    // Moves the elements into the table.
    $form['field_properties']['tbody']['components'][$key] = $form['components'][$key];
    $form['field_properties']['tbody']['components'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['components'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['components'][$key]['#weight'] = $i;
    $form['field_properties']['tbody']['minimum_components'][$key] = $form['minimum_components'][$key];
    $form['field_properties']['tbody']['minimum_components'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['minimum_components'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['minimum_components'][$key]['#weight'] = $i;
    $form['field_properties']['tbody']['max_length'][$key] = $form['max_length'][$key];
    $form['field_properties']['tbody']['max_length'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['max_length'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['max_length'][$key]['#weight'] = $i;
    $form['field_properties']['tbody']['labels'][$key] = $form['labels'][$key];
    $form['field_properties']['tbody']['labels'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['labels'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['labels'][$key]['#weight'] = $i;
    if (isset($form['sort_options'][$key])) {
      $form['field_properties']['tbody']['sort_options'][$key] = $form['sort_options'][$key];
    }
    else {
      $form['field_properties']['tbody']['sort_options'][$key] = array(
        '#markup' => '&nbsp;',
      );
    }
    $form['field_properties']['tbody']['sort_options'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['sort_options'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['sort_options'][$key]['#weight'] = $i;
    $form['field_properties']['tbody']['autocomplete_source'][$key] = $form['autocomplete_source'][$key];
    $form['field_properties']['tbody']['autocomplete_source'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['autocomplete_source'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['autocomplete_source'][$key]['#weight'] = $i;
    $form['field_properties']['tbody']['autocomplete_separator'][$key] = $form['autocomplete_separator'][$key];
    $form['field_properties']['tbody']['autocomplete_separator'][$key]['#prefix'] = '<td>';
    $form['field_properties']['tbody']['autocomplete_separator'][$key]['#suffix'] = '</td>';
    $form['field_properties']['tbody']['autocomplete_separator'][$key]['#weight'] = $i;

    // Clean up the leftovers.
    unset($form['components'][$key]);
    $form['components']['#access'] = FALSE;
    unset($form['minimum_components'][$key]);
    $form['minimum_components']['#access'] = FALSE;
    unset($form['max_length'][$key]);
    $form['max_length']['#access'] = FALSE;
    unset($form['labels'][$key]);
    $form['labels']['#access'] = FALSE;
    if (isset($form['sort_options'][$key])) {
      unset($form['sort_options'][$key]);
      $form['sort_options']['#access'] = FALSE;
    }
    unset($form['autocomplete_source'][$key]);
    $form['autocomplete_source']['#access'] = FALSE;
    unset($form['autocomplete_separator'][$key]);
    $form['autocomplete_separator']['#access'] = FALSE;
  }

  // Move the additional options under the table.
  $form['extra_fields'] = array(
    '#weight' => 2,
  );
  $form['title_options']['#weight'] = 0;
  $form['generational_options']['#weight'] = 1;
  $form['extra_fields']['title_options'] = $form['title_options'];
  $form['extra_fields']['generational_options'] = $form['generational_options'];
  unset($form['title_options']);
  unset($form['generational_options']);
  return $form;
}