You are here

public function ViewUI::submitDisplaysReorderForm in Views (for Drupal 7) 8.3

Submit handler for rearranging display form

File

views_ui/lib/Drupal/views_ui/ViewUI.php, line 1551
Definition of Drupal\views_ui\ViewUI.

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function submitDisplaysReorderForm($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 = 1;
  foreach (array_keys($order) as $display) {
    $order[$display] = $position++;
  }

  // Setting up position and removing deleted displays
  $displays = $this->storage->display;
  foreach ($displays as $display_id => $display) {

    // Don't touch the default !!!
    if ($display_id === 'default') {
      $this->storage->display[$display_id]['position'] = 0;
      continue;
    }
    if (isset($order[$display_id])) {
      $this->storage->display[$display_id]['position'] = $order[$display_id];
    }
    else {
      $this->storage->display[$display_id]['deleted'] = TRUE;
    }
  }

  // Sorting back the display array as the position is not enough
  uasort($this->storage->display, array(
    'static',
    'sortPosition',
  ));

  // Store in cache
  views_ui_cache_set($this);
  $form_state['redirect'] = array(
    'admin/structure/views/view/' . $this->storage->name . '/edit',
    array(
      'fragment' => 'views-tab-default',
    ),
  );
}