You are here

public function YamlFormHandlerFormBase::submitForm in YAML Form 8

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/YamlFormHandlerFormBase.php, line 168

Class

YamlFormHandlerFormBase
Provides a base form for form handlers.

Namespace

Drupal\yamlform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($response = $this
    ->validateDialog($form, $form_state)) {
    return $response;
  }
  $form_state
    ->cleanValues();

  // The form handler configuration is stored in the 'settings' key in
  // the form, pass that through for submission.
  $handler_data = (new FormState())
    ->setValues($form_state
    ->getValue('settings'));
  $this->yamlformHandler
    ->submitConfigurationForm($form, $handler_data);

  // Update the original form values.
  $form_state
    ->setValue('settings', $handler_data
    ->getValues());
  $is_new = $this->yamlformHandler
    ->getHandlerId() ? FALSE : TRUE;
  $this->yamlformHandler
    ->setHandlerId($form_state
    ->getValue('handler_id'));
  $this->yamlformHandler
    ->setLabel($form_state
    ->getValue('label'));
  $this->yamlformHandler
    ->setStatus($form_state
    ->getValue('status'));
  $this->yamlformHandler
    ->setWeight($form_state
    ->getValue('weight'));
  if ($is_new) {
    $this->yamlform
      ->addYamlFormHandler($this->yamlformHandler
      ->getConfiguration());
  }
  $this->yamlform
    ->save();

  // Display status message.
  drupal_set_message($this
    ->t('The form handler was successfully applied.'));

  // Redirect.
  return $this
    ->redirectForm($form, $form_state, $this->yamlform
    ->toUrl('handlers-form'));
}