You are here

public function ConfigHandler::submitForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Form/Ajax/ConfigHandler.php \Drupal\views_ui\Form\Ajax\ConfigHandler::submitForm()

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/ConfigHandler.php, line 212
Contains \Drupal\views_ui\Form\Ajax\ConfigHandler.

Class

ConfigHandler
Provides a form for configuring an item in the Views UI.

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');
  $id = $form_state
    ->get('id');
  $handler = $form_state
    ->get('handler');

  // Run it through the handler's submit function.
  $handler
    ->submitOptionsForm($form['options'], $form_state);
  $item = $handler->options;
  $types = ViewExecutable::getHandlerTypes();

  // For footer/header $handler_type is area but $type is footer/header.
  // For all other handle types it's the same.
  $handler_type = $type = $form_state
    ->get('type');
  if (!empty($types[$type]['type'])) {
    $handler_type = $types[$type]['type'];
  }
  $override = NULL;
  $executable = $view
    ->getExecutable();
  if ($executable->display_handler
    ->useGroupBy() && !empty($item['group_type'])) {
    if (empty($executable->query)) {
      $executable
        ->initQuery();
    }
    $aggregate = $executable->query
      ->getAggregationInfo();
    if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
      $override = $aggregate[$item['group_type']]['handler'][$type];
    }
  }

  // Create a new handler and unpack the options from the form onto it. We
  // can use that for storage.
  $handler = Views::handlerManager($handler_type)
    ->getHandler($item, $override);
  $handler
    ->init($executable, $executable->display_handler, $item);

  // Add the incoming options to existing options because items using
  // the extra form may not have everything in the form here.
  $options = $form_state
    ->getValue('options') + $handler->options;

  // This unpacks only options that are in the definition, ensuring random
  // extra stuff on the form is not sent through.
  $handler
    ->unpackOptions($handler->options, $options, NULL, FALSE);

  // Store the item back on the view
  $executable
    ->setHandler($display_id, $type, $id, $handler->options);

  // Ensure any temporary options are removed.
  if (isset($view->temporary_options[$type][$id])) {
    unset($view->temporary_options[$type][$id]);
  }

  // Write to cache
  $view
    ->cacheSet();
}