function FormWizardBase::submitForm

Same name and namespace in other branches
  1. 4.0.x src/Wizard/FormWizardBase.php \Drupal\ctools\Wizard\FormWizardBase::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 FormInterface::submitForm

File

src/Wizard/FormWizardBase.php, line 284

Class

FormWizardBase
The base class for all form wizard.

Namespace

Drupal\ctools\Wizard

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  // Only perform this logic if we're moving to the next page. This prevents
  // the loss of cached values on ajax submissions.
  if ((string) $form_state->getValue('op') == (string) $this->getNextOp()) {
    $cached_values = $form_state->getTemporaryValue('wizard');
    if ($form_state->hasValue('label')) {
      $cached_values['label'] = $form_state->getValue('label');
    }
    if ($form_state->hasValue('id')) {
      $cached_values['id'] = $form_state->getValue('id');
    }
    if (is_null($this->machine_name) && !empty($cached_values['id'])) {
      $this->machine_name = $cached_values['id'];
    }
    $this->getTempstore()
      ->set($this->getMachineName(), $cached_values);
    $next_parameters = $this->getNextParameters($cached_values);
    if (!$form_state->get('ajax')) {
      $form_state->setRedirect($this->getRouteName(), $next_parameters);
    }
    else {
      // Switch steps for ajax forms.
      if (!empty($next_parameters['step'])) {
        $this->step = $next_parameters['step'];
      }
    }
  }
}