1 views_ui.admin.inc | views_ui_reorder_displays_form_submit($form, &$form_state) |
Submit handler for rearranging display form
File
- core/
modules/ views_ui/ views_ui.admin.inc, line 3091 - Admin page callbacks for the Views UI module.
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, function($display1, $display2) {
if ($display1->position != $display2->position) {
return $display1->position < $display2->position ? -1 : 1;
}
return 0;
});
// Store in cache
views_ui_cache_set($form_state['view']);
$form_state['redirect'] = array('admin/structure/views/view/' . $form_state['view']->name . '/configure', array('fragment' => 'views-tab-default'));
}