You are here

function _name_field_instance_settings_pre_render in Name Field 6

Same name and namespace in other branches
  1. 7 name.admin.inc \_name_field_instance_settings_pre_render()

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

1 call to _name_field_instance_settings_pre_render()
name_field_instance_settings_pre_render in ./name.module

File

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

Code

function _name_field_instance_settings_pre_render($form) {
  $form['instance_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,
      'title_display' => array(
        '#prefix' => '<tr><td><strong>' . t('Title display') . ' <sup>1</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 1,
      ),
      'size' => array(
        '#prefix' => '<tr><td><strong>' . t('HTML size') . ' <sup>2</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 2,
      ),
      'inline_css_enabled' => array(
        '#prefix' => '<tr><td><strong>' . t('Inline style') . ' <sup>3</sup></strong></td>',
        '#suffix' => '</tr>',
        '#weight' => 3,
      ),
    ),
    'tfoot' => array(
      '#value' => '<tfoot><tr><td colspan="6"><ol>' . '<li>' . t('The title display controls how the label of the name component is displayed in the form. "%above" is the standard title; "%below" is the standard description; "%hidden" removes the label.', array(
        '%above' => t('above'),
        '%below' => t('below'),
        '%hidden' => t('hidden'),
      )) . '</li>' . '<li>' . t('The HTML size property tells the browser what the width of the field should be when it is rendered. This gets overriden by the themes CSS properties. This must be between 1 and 255.') . '</li>' . '<li>' . t('The inline style property tells the browser what the width of the field <strong>really</strong> should be when it is rendered. This is dynamically calculated from the HTML size property.') . '</li>' . '</ol></td></tr></tfoot>',
      '#weight' => 2,
    ),
    'extra_fields' => array(
      '#weight' => 3,
    ),
  );
  $i = 0;
  foreach (_name_translations() as $key => $title) {

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

    // Strip the title & description.
    unset($form['size'][$key]['#description']);
    unset($form['size'][$key]['#title']);
    $form['size'][$key]['#size'] = 5;
    unset($form['title_display'][$key]['#description']);
    unset($form['title_display'][$key]['#title']);
    unset($form['inline_css_enabled'][$key]['#description']);
    unset($form['inline_css_enabled'][$key]['#title']);

    // Moves the size element into the table.
    $form['instance_properties']['tbody']['size'][$key] = $form['size'][$key];
    $form['instance_properties']['tbody']['size'][$key]['#prefix'] = '<td>';
    $form['instance_properties']['tbody']['size'][$key]['#suffix'] = '</td>';
    $form['instance_properties']['tbody']['size'][$key]['#weight'] = $i;
    $form['instance_properties']['tbody']['title_display'][$key] = $form['title_display'][$key];
    $form['instance_properties']['tbody']['title_display'][$key]['#prefix'] = '<td>';
    $form['instance_properties']['tbody']['title_display'][$key]['#suffix'] = '</td>';
    $form['instance_properties']['tbody']['title_display'][$key]['#weight'] = $i;
    $form['instance_properties']['tbody']['inline_css_enabled'][$key] = $form['inline_css_enabled'][$key];
    $form['instance_properties']['tbody']['inline_css_enabled'][$key]['#prefix'] = '<td>';
    $form['instance_properties']['tbody']['inline_css_enabled'][$key]['#suffix'] = '</td>';
    $form['instance_properties']['tbody']['inline_css_enabled'][$key]['#weight'] = $i;

    // Clean up the leftovers.
    unset($form['size'][$key]);
    $form['size']['#access'] = FALSE;
    unset($form['title_display'][$key]);
    $form['title_display']['#access'] = FALSE;
    unset($form['inline_css_enabled'][$key]);
    $form['inline_css_enabled']['#access'] = FALSE;
  }

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