You are here

public function ViewAddForm::validateForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/src/ViewAddForm.php \Drupal\views_ui\ViewAddForm::validateForm()

Form validation 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 FormBase::validateForm

File

core/modules/views_ui/src/ViewAddForm.php, line 163

Class

ViewAddForm
Form controller for the Views add form.

Namespace

Drupal\views_ui

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $wizard_type = $form_state
    ->getValue([
    'show',
    'wizard_key',
  ]);
  $wizard_instance = $this->wizardManager
    ->createInstance($wizard_type);
  $form_state
    ->set('wizard', $wizard_instance
    ->getPluginDefinition());
  $form_state
    ->set('wizard_instance', $wizard_instance);
  $path =& $form_state
    ->getValue([
    'page',
    'path',
  ]);
  if (!empty($path)) {

    // @todo https://www.drupal.org/node/2423913 Views should expect and store
    //   a leading /.
    $path = ltrim($path, '/ ');
  }
  $errors = $wizard_instance
    ->validateView($form, $form_state);
  foreach ($errors as $display_errors) {
    foreach ($display_errors as $name => $message) {
      $form_state
        ->setErrorByName($name, $message);
    }
  }
}