Turn the rearrange form into a proper table
function theme_views_ui_rearrange_filter_form(&$vars) {
$form = $vars['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 ($group_id !== 'ungroupable') {
// Set up tabledrag so that it changes the group dropdown when rows are
// dragged between groups.
drupal_add_tabledrag('views-rearrange-filters', 'match', 'sibling', 'views-group-select', 'views-group-select-' . $group_id);
// Title row, spanning all columns.
$row = array();
// Add a cell to the first row, containing the group operator.
$row[] = array(
'class' => array(
'group',
'group-operator',
'container-inline',
),
'data' => drupal_render($form['filter_groups']['groups'][$group_id]),
'rowspan' => max(array(
2,
count($contents) + 1,
)),
);
// Title.
$row[] = array(
'class' => array(
'group',
'group-title',
),
'data' => '<span>' . $form['#group_options'][$group_id] . '</span>',
'colspan' => 4,
);
$rows[] = array(
'class' => array(
'views-group-title',
),
'data' => $row,
'id' => 'views-group-title-' . $group_id,
);
// Row which will only appear if the group has nothing in it.
$row = array();
$class = 'group-' . (count($contents) ? 'populated' : 'empty');
$instructions = '<span>' . t('No filters have been added.') . '</span> <span class="js-only">' . t('Drag to add filters.') . '</span>';
// When JavaScript is enabled, the button for removing the group (if it's
// present) should be hidden, since it will be replaced by a link on the
// client side.
if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') {
$form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide';
}
$row[] = array(
'colspan' => 5,
'data' => $instructions . drupal_render($form['remove_groups'][$group_id]),
);
$rows[] = array(
'class' => array(
"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'] = array(
'weight',
);
$row[] = drupal_render($form['filters'][$id]['weight']);
$form['filters'][$id]['group']['#attributes']['class'] = array(
'views-group-select views-group-select-' . $group_id,
);
$row[] = drupal_render($form['filters'][$id]['group']);
$form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide';
$row[] = drupal_render($form['filters'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array(
'attributes' => array(
'id' => 'views-remove-link-' . $id,
'class' => array(
'views-hidden',
'views-button-remove',
'views-groups-remove-link',
'views-remove-link',
),
'alt' => t('Remove this item'),
'title' => t('Remove this item'),
),
'html' => TRUE,
));
$row = array(
'data' => $row,
'class' => array(
'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']);
$output .= '<div class="scroll">';
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('views-rearrange-filters-ungroupable', 'order', 'sibling', 'weight');
$header = array(
t('Ungroupable filters'),
t('Weight'),
array(
'class' => array(
'views-hide-label',
),
'data' => t('Group'),
),
array(
'class' => array(
'views-hide-label',
),
'data' => t('Remove'),
),
);
$output .= theme('table', array(
'header' => $header,
'rows' => $ungroupable_rows,
'attributes' => array(
'id' => 'views-rearrange-filters-ungroupable',
'class' => array(
'arrange',
),
),
));
}
// Set up tabledrag so that the weights are changed when rows are dragged.
drupal_add_tabledrag('views-rearrange-filters', 'order', 'sibling', 'weight');
$output .= theme('table', array(
'rows' => $rows,
'attributes' => array(
'id' => 'views-rearrange-filters',
'class' => array(
'arrange',
),
),
));
$output .= '</div>';
// When JavaScript is enabled, the button for adding a new group should be
// hidden, since it will be replaced by a link on the client side.
$form['buttons']['add_group']['#attributes']['class'][] = 'js-hide';
// Render the rest of the form and return.
$output .= drupal_render_children($form);
return $output;
}