function ViewAddForm::submitForm

Same name in other branches
  1. 8.9.x core/modules/views_ui/src/ViewAddForm.php \Drupal\views_ui\ViewAddForm::submitForm()
  2. 10 core/modules/views_ui/src/ViewAddForm.php \Drupal\views_ui\ViewAddForm::submitForm()
  3. 11.x core/modules/views_ui/src/ViewAddForm.php \Drupal\views_ui\ViewAddForm::submitForm()

Overrides EntityForm::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'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.