public function Rearrange::submitForm

Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm().

Overrides ViewsFormBase::submitForm

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php, line 137
Contains \Drupal\views_ui\Form\Ajax\Rearrange.

Class

Rearrange
Provides a rearrange form for Views handlers.

Namespace

Drupal\views_ui\Form\Ajax

Code

public function submitForm(array &$form, array &$form_state) {
  $types = ViewExecutable::viewsHandlerTypes();
  $display =& $form_state['view']
    ->get('executable')->displayHandlers
    ->get($form_state['display_id']);
  $old_fields = $display
    ->getOption($types[$form_state['type']]['plural']);
  $new_fields = $order = array();

  // Make an array with the weights
  foreach ($form_state['values']['fields'] as $field => $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[$field] = $info['weight'];
    }
  }

  // Sort the array
  asort($order);

  // Create a new list of fields in the new order.
  foreach (array_keys($order) as $field) {
    $new_fields[$field] = $old_fields[$field];
  }
  $display
    ->setOption($types[$form_state['type']]['plural'], $new_fields);

  // Store in cache
  $form_state['view']
    ->cacheSet();
}