You are here

public function YamlFormUiElementFormBase::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

1 method overrides YamlFormUiElementFormBase::submitForm()
YamlFormUiElementTestForm::submitForm in modules/yamlform_ui/src/Form/YamlFormUiElementTestForm.php
Form submission handler.

File

modules/yamlform_ui/src/Form/YamlFormUiElementFormBase.php, line 288

Class

YamlFormUiElementFormBase
Provides a base class for form element forms.

Namespace

Drupal\yamlform_ui\Form

Code

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

  // The form element configuration is stored in the 'properties' key in
  // the form, pass that through for submission.
  $element_form_state = clone $form_state;
  $element_form_state
    ->setValues($form_state
    ->getValue('properties'));

  // Submit element configuration.
  // Generally, elements will not be processing any submitted properties.
  // It is possible that a custom element might need to call a third-party API
  // to 'register' the element.
  $yamlform_element
    ->submitConfigurationForm($form, $element_form_state);

  // Save the form with its updated element.
  $this->yamlform
    ->save();

  // Display status message.
  $properties = $form_state
    ->getValue('properties');
  $t_args = [
    '%title' => !empty($properties['title']) ? $properties['title'] : $form_state
      ->getValue('key'),
    '@action' => $this->action,
  ];
  drupal_set_message($this
    ->t('%title has been @action.', $t_args));

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