You are here

function template_preprocess_ds_display_overview_views_form in Display Suite 6

Same name and namespace in other branches
  1. 6.3 theme/theme_ui.inc \template_preprocess_ds_display_overview_views_form()
  2. 6.2 theme/theme_ui.inc \template_preprocess_ds_display_overview_views_form()

Theme preprocess function for ds-display-overview-views-form.tpl.php.

File

theme/theme_ui.inc, line 187
Theming functions for ds ui.

Code

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

  // Sort fields.
  $order = array();
  $root_fields = array();
  $leaf_fields = array();
  foreach ($form['#fields'] as $key => $field) {
    if (!empty($form[$field][$build_mode]['parent_id']['#default_value'])) {
      $leaf_fields[$form[$field][$build_mode]['parent_id']['#default_value']][$field] = $form[$field]['ds_weight']['#default_value'];
    }
    else {
      $root_fields[$field] = $form[$field]['ds_weight']['#default_value'];
    }
  }
  asort($root_fields);
  foreach ($root_fields as $root_field => $root_weight) {
    $order[$root_field] = $root_weight;
    if (isset($leaf_fields[$root_field])) {
      $fields_in_leaf = $leaf_fields[$root_field];
      asort($fields_in_leaf);
      foreach ($fields_in_leaf as $leaf_field => $leaf_weight) {
        $order[$leaf_field] = $leaf_weight;
      }
    }
  }
  $rows = array();
  foreach ($order as $field => $field_weight) {
    $element =& $form[$field];
    $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}->indentation = theme('indentation', $element[$child]['#depth']);
        if (empty($element[$child]['css-class']['#options'])) {
          $element[$child]['css-class']['#access'] = FALSE;
        }
        $row->{$child}->class = drupal_render($element[$child]['css-class']);
        $row->{$child}->label = drupal_render($element[$child]['label']);

        // Parent & Field id.
        $row->{$child}->parent_id = drupal_render($element[$child]['parent_id']);
        $row->{$child}->field_id = drupal_render($element[$child]['field_id']);

        // Extra classes when fieldgroup.
        if ($element[$child]['type']['#value'] == DS_FIELD_TYPE_GROUP) {
          $element[$child]['format']['#attributes']['class'] = 'fieldgroup-format';
          if (substr($element[$child]['format']['#default_value'], 0, 17) == 'ds_group_fieldset' || substr($element[$child]['format']['#default_value'], 0, 7) == 'ds_tabs') {
            $element[$child]['label']['format']['#attributes']['class'] = 'ds-hidden';
          }
        }

        // Hide region.
        if (!empty($element[$child]['parent_id']['#default_value'])) {
          $element[$child]['region']['#attributes']['class'] .= ' ds-hidden';
        }
        $row->{$child}->region = drupal_render($element[$child]['region']);
      }
      else {

        // Process weight.
        if ($child == 'ds_weight') {
          $element['ds_weight']['#attributes']['class'] = 'field-weight field-weight-' . $region;
          $element['ds_weight'] = process_weight($element['ds_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';
    if ($element[$build_mode]['type']['#value'] == DS_FIELD_TYPE_GROUP) {
      $row->label_class .= ' field-group';
      $row->class .= ' tabledrag-root';
    }
    else {
      $row->class .= ' tabledrag-leaf';
    }

    // Add to rows.
    $rows[$region][] = $row;
  }
  $vars['rows'] = $rows;
  $vars['submit'] = drupal_render($form);
  $vars['regions'] = $form['#regions'];
  $vars['build_mode'] = $build_mode;
}