public Rearrange::submitForm(array &$form, FormStateInterface $form_state)
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ViewsFormBase::submitForm
File
- core/modules/views_ui/src/Form/Ajax/Rearrange.php, line 146
Class
- Rearrange
- Provides a rearrange form for Views handlers.
Namespace
Drupal\views_ui\Form\Ajax
Code
public function submitForm(array &$form, FormStateInterface $form_state) { $view = $form_state->get('view'); $display_id = $form_state->get('display_id'); $type = $form_state->get('type'); $types = ViewExecutable::getHandlerTypes(); $display = &$view->getExecutable()->displayHandlers->get($display_id); $old_fields = $display->getOption($types[$type]['plural']); $new_fields = $order = array(); // Make an array with the weights foreach ($form_state->getValue('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[$type]['plural'], $new_fields); // Store in cache $view->cacheSet(); }
Please login to continue.