You are here

function template_preprocess_nd_display_overview_form in Node displays 6

Theme preprocess function for nd-display-overview-form.tpl.php.

We are overriding the complete theming function to add weights and regions which will be saved automatically in the display settings.

File

theme/theme.inc, line 70
Theming functions for nd.

Code

function template_preprocess_nd_display_overview_form(&$vars) {
  $form =& $vars['form'];
  $build_mode = $form['#build_mode'];

  // Order the fields.
  $order = array();
  foreach ($form['#fields'] as $key => $field) {
    $order[$field] = $form[$field]['nd_weight']['#default_value'];
  }
  asort($order);

  // Render exclude build mode checkbox.
  $vars['exclude_build_mode'] = drupal_render($form['exclude_build_mode']);
  $rows = array();
  foreach ($order as $key => $field) {
    $element =& $form[$key];
    $row = new stdClass();

    // Each field will have a region, store it temporarily
    $region = $element[$build_mode]['region']['#default_value'];
    foreach (element_children($element) as $child) {

      // Render the display fields
      if ($child == $build_mode) {
        $row->{$child}->label = drupal_render($element[$child]['label']);
        $row->{$child}->format = drupal_render($element[$child]['format']);
        $row->{$child}->region = drupal_render($element[$child]['region']);
      }
      else {

        // Process weight.
        if ($child == 'nd_weight') {
          $element['nd_weight']['#attributes']['class'] = 'field-weight field-weight-' . $region;
          $element['nd_weight'] = process_weight($element['nd_weight']);
        }
        $row->{$child} = drupal_render($element[$child]);
      }
    }

    // Add draggable.
    $row->class = 'draggable';
    if ($region == 'disabled') {
      $row->class .= ' region-css-' . $region;
    }
    $row->label_class = 'label-field';
    $rows[$region][] = $row;
  }
  drupal_add_js('misc/tableheader.js');
  drupal_add_js(drupal_get_path('module', 'nd') . '/js/nd.js');
  drupal_add_css(drupal_get_path('module', 'nd') . '/css/nd.css');
  $regions = nd_regions($build_mode);
  foreach ($regions as $region => $title) {
    drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-' . $region, NULL, FALSE);

    // We need to have subgroups to make the dragging available within parents
    drupal_add_tabledrag('fields', 'order', 'sibling', 'field-weight', 'field-weight-' . $region);
  }

  // Plugins available.
  if (isset($form['#plugins'])) {
    $vars['plugins'] = TRUE;
    $vars['plugins_content'] = '';
    foreach ($form['#plugin_keys'] as $key) {
      $vars['plugins_content'] .= drupal_render($form[$key]);
    }
  }
  $vars['submit'] = drupal_render($form);
  $vars['regions'] = $regions;
  $vars['rows'] = $rows;
  $vars['build_mode'] = $build_mode;
  $vars['extra_style'] = $form['exclude_build_mode']['#default_value'] == TRUE ? 'style="display: none;"' : '';
}