You are here

public function WebformVariantFormBase::submitForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformVariantFormBase.php \Drupal\webform\Form\WebformVariantFormBase::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/Form/WebformVariantFormBase.php, line 277

Class

WebformVariantFormBase
Provides a base webform for webform variants.

Namespace

Drupal\webform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state
    ->cleanValues();

  // The webform variant configuration is stored in the 'settings' key in
  // the webform, pass that through for submission.
  $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
  $this->webformVariant
    ->submitConfigurationForm($form, $subform_state);

  // Update the original webform values.
  $form_state
    ->setValue('settings', $subform_state
    ->getValues());
  $this->webformVariant
    ->setVariantId($form_state
    ->getValue('variant_id'));
  $this->webformVariant
    ->setLabel($form_state
    ->getValue('label'));
  $this->webformVariant
    ->setNotes($form_state
    ->getValue('notes'));
  $this->webformVariant
    ->setElementKey($form_state
    ->getValue('element_key'));
  $this->webformVariant
    ->setStatus($form_state
    ->getValue('status'));
  $this->webformVariant
    ->setWeight($form_state
    ->getValue('weight'));
  if ($this instanceof WebformVariantAddForm) {
    $this->webform
      ->addWebformVariant($this->webformVariant);
    $this
      ->messenger()
      ->addStatus($this
      ->t('The webform variant was successfully added.'));
  }
  else {
    $this->webform
      ->updateWebformVariant($this->webformVariant);
    $this
      ->messenger()
      ->addStatus($this
      ->t('The webform variant was successfully updated.'));
  }
  $form_state
    ->setRedirectUrl($this->webform
    ->toUrl('variants', [
    'query' => [
      'update' => $this->webformVariant
        ->getVariantId(),
    ],
  ]));
}