You are here

function theme_views_ui_rearrange_filter_form in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 8.3 views_ui/theme/theme.inc \theme_views_ui_rearrange_filter_form()
  2. 7.3 includes/admin.inc \theme_views_ui_rearrange_filter_form()

Turn the rearrange form into a proper table

File

includes/admin.inc, line 2846
admin.inc Provides the Views' administrative interface.

Code

function theme_views_ui_rearrange_filter_form($form) {
  $rows = $ungroupable_rows = array();

  // Enable grouping only if > 1 group.
  $grouping = count(array_keys($form['#group_options'])) > 1;
  foreach ($form['#group_renders'] as $group_id => $contents) {

    // Header row for the group.
    if ($grouping && $group_id !== 'ungroupable') {
      $row = array();
      $row[] = array(
        'class' => 'group group-title',
        'data' => $form['#group_options'][$group_id],
      );
      $row[] = array(
        'class' => 'group container-inline',
        'data' => drupal_render($form['filter_groups']['groups'][$group_id]),
        'colspan' => 3,
      );
      $rows[] = array(
        'class' => 'views-group',
        'data' => $row,
        'id' => 'views-group-' . $group_id,
      );

      // Row which will only appear if the group has nothing in it:
      $row = array();
      $class = 'group-' . (count($contents) ? 'populated' : 'empty');
      $row[] = array(
        'colspan' => 4,
        'data' => '<span>' . t('This group is empty') . '</span> ' . drupal_render($form['remove_groups'][$group_id]),
      );
      $rows[] = array(
        'class' => "group-message group-{$group_id}-message " . $class,
        'data' => $row,
        'id' => 'views-group-' . $group_id,
      );
    }
    foreach ($contents as $id) {
      if (isset($form['filters'][$id]['name'])) {
        $row = array();
        $row[] = drupal_render($form['filters'][$id]['name']);
        $form['filters'][$id]['weight']['#attributes']['class'] = 'weight';
        $row[] = drupal_render($form['filters'][$id]['weight']);
        $form['filters'][$id]['group']['#attributes']['class'] = 'views-group-select views-group-' . $group_id;
        $row[] = drupal_render($form['filters'][$id]['group']);
        $row[] = drupal_render($form['filters'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array(
          'attributes' => array(
            'id' => 'views-remove-link-' . $id,
            'class' => 'views-hidden views-button-remove views-groups-remove-link',
            'alt' => t('Remove this item'),
            'title' => t('Remove this item'),
          ),
          'html' => true,
        ));
        $row = array(
          'data' => $row,
          'class' => 'draggable',
          'id' => 'views-row-' . $id,
        );
        if ($group_id !== 'ungroupable') {
          $rows[] = $row;
        }
        else {
          $ungroupable_rows[] = $row;
        }
      }
    }
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No fields available.'),
        'colspan' => '2',
      ),
    );
  }
  $output = drupal_render($form['override']);
  if ($grouping) {
    $output .= drupal_render($form['filter_groups']['operator']);
  }
  else {
    $form['filter_groups']['groups'][0]['#title'] = t('Operator');
    $output .= drupal_render($form['filter_groups']['groups'][0]);
  }
  if (!empty($ungroupable_rows)) {
    drupal_add_tabledrag('ungroupable_arrange', 'order', 'sibling', 'weight');
    $header = array(
      t('Ungroupable filters'),
      t('Weight'),
      array(
        'class' => 'views-hide-label',
        'data' => t('Group'),
      ),
      array(
        'class' => 'views-hide-label',
        'data' => t('Remove'),
      ),
    );
    $output .= theme('table', $header, $ungroupable_rows, array(
      'id' => 'ungroupable_arrange',
      'class' => 'arrange',
    ));
  }
  drupal_add_tabledrag('arrange', 'order', 'sibling', 'weight');
  $header = array(
    '',
    t('Weight'),
    t('Group'),
    t('Remove'),
  );
  $output .= theme('table', $header, $rows, array(
    'id' => 'arrange',
    'class' => 'arrange',
  ));
  $output .= drupal_render($form);
  return $output;
}