function views_ui_reorder_displays_form_submit in Views (for Drupal 7) 6.3
Same name and namespace in other branches
- 7.3 includes/admin.inc \views_ui_reorder_displays_form_submit()
Submit handler for rearranging display form
File
Code
function views_ui_reorder_displays_form_submit($form, &$form_state) {
foreach ($form_state['input'] as $display => $info) {
// add each value that is a field with a weight to our list, but only if
// it has had its 'removed' checkbox checked.
if (is_array($info) && isset($info['weight']) && empty($info['removed'])) {
$order[$display] = $info['weight'];
}
}
// Sort the order array
asort($order);
// Fixing up positions
$position = 2;
foreach (array_keys($order) as $display) {
$order[$display] = $position++;
}
// Setting up position and removing deleted displays
$displays = $form_state['view']->display;
foreach ($displays as $display_id => $display) {
// Don't touch the default !!!
if ($display_id === 'default') {
continue;
}
if (isset($order[$display_id])) {
$form_state['view']->display[$display_id]->position = $order[$display_id];
}
else {
$form_state['view']->display[$display_id]->deleted = TRUE;
}
}
// Sorting back the display array as the position is not enough
uasort($form_state['view']->display, '_views_position_sort');
// Store in cache
views_ui_cache_set($form_state['view']);
$form_state['redirect'] = array(
'admin/build/views/edit/' . $form_state['view']->name,
NULL,
'views-tab-default',
);
}