You are here

public function ViewAddForm::submitForm in Zircon Profile 8

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

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

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 EntityForm::submitForm

File

core/modules/views_ui/src/ViewAddForm.php, line 182
Contains \Drupal\views_ui\ViewAddForm.

Class

ViewAddForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

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

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