function views_ui_reorder_displays_form_submit

Submit handler for rearranging display form.

File

includes/admin.inc, line 3260

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/structure/views/view/' . $form_state['view']->name . '/edit',
        array(
            'fragment' => 'views-tab-default',
        ),
    );
}