You are here

public function ViewAddForm::submitForm in Drupal 10

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

File

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

Class

ViewAddForm
Form controller for the Views add form.

Namespace

Drupal\views_ui

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  try {

    /** @var \Drupal\views\Plugin\views\wizard\WizardInterface $wizard */
    $wizard = $form_state
      ->get('wizard_instance');
    $this->entity = $wizard
      ->createView($form, $form_state);
  } catch (WizardException $e) {
    $this
      ->messenger()
      ->addError($e
      ->getMessage());
    $form_state
      ->setRedirect('entity.view.collection');
    return;
  }
  $this->entity
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('The view %name has been saved.', [
    '%name' => $form_state
      ->getValue('label'),
  ]));
  $form_state
    ->setRedirectUrl($this->entity
    ->toUrl('edit-form'));
}