You are here

function views_ui_rearrange_form_submit in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 6.3 includes/admin.inc \views_ui_rearrange_form_submit()
  2. 6.2 includes/admin.inc \views_ui_rearrange_form_submit()
  3. 7.3 includes/admin.inc \views_ui_rearrange_form_submit()

Submit handler for rearranging form.

File

views_ui/admin.inc, line 1204
Provides the Views' administrative interface.

Code

function views_ui_rearrange_form_submit($form, &$form_state) {
  $types = ViewUI::viewsHandlerTypes();
  $display =& $form_state['view']->displayHandlers[$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'] 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
  views_ui_cache_set($form_state['view']);
}