You are here

public function WebformHandlerFormBase::submitForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/WebformHandlerFormBase.php \Drupal\webform\Form\WebformHandlerFormBase::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/WebformHandlerFormBase.php, line 314

Class

WebformHandlerFormBase
Provides a base webform for webform handlers.

Namespace

Drupal\webform\Form

Code

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

  // The webform handler 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->webformHandler
    ->submitConfigurationForm($form, $subform_state);

  // Update the original webform values.
  $form_state
    ->setValue('settings', $subform_state
    ->getValues());
  $this->webformHandler
    ->setHandlerId($form_state
    ->getValue('handler_id'));
  $this->webformHandler
    ->setLabel($form_state
    ->getValue('label'));
  $this->webformHandler
    ->setNotes($form_state
    ->getValue('notes'));
  $this->webformHandler
    ->setStatus($form_state
    ->getValue('status'));
  $this->webformHandler
    ->setWeight($form_state
    ->getValue('weight'));

  // Clear conditions if conditions or handler is disabled.
  if (!$this->webformHandler
    ->supportsConditions() || $this->webformHandler
    ->isDisabled()) {
    $this->webformHandler
      ->setConditions([]);
  }
  else {
    $this->webformHandler
      ->setConditions($form_state
      ->getValue('conditions'));
  }
  if ($this instanceof WebformHandlerAddForm) {
    $this->webform
      ->addWebformHandler($this->webformHandler);
    $this
      ->messenger()
      ->addStatus($this
      ->t('The webform handler was successfully added.'));
  }
  else {
    $this->webform
      ->updateWebformHandler($this->webformHandler);
    $this
      ->messenger()
      ->addStatus($this
      ->t('The webform handler was successfully updated.'));
  }
  $form_state
    ->setRedirectUrl($this->webform
    ->toUrl('handlers', [
    'query' => [
      'update' => $this->webformHandler
        ->getHandlerId(),
    ],
  ]));
}