You are here

public function FieldValidationRuleFormBase::submitForm in Field Validation 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/FieldValidationRuleFormBase.php, line 251

Class

FieldValidationRuleFormBase
Provides a base form for FieldValidationRule.

Namespace

Drupal\field_validation\Form

Code

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

  //drupal_flush_all_caches();

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

  // Update the original form values.
  $form_state
    ->setValue('data', $field_validation_rule_data
    ->getValues());
  $this->fieldValidationRule
    ->setTitle($form_state
    ->getValue('title'));
  $this->fieldValidationRule
    ->setWeight($form_state
    ->getValue('weight'));
  $this->fieldValidationRule
    ->setFieldName($form_state
    ->getValue('field_name'));
  $this->fieldValidationRule
    ->setColumn($form_state
    ->getValue('column'));
  $this->fieldValidationRule
    ->setErrorMessage($form_state
    ->getValue('error_message'));
  if (!$this->fieldValidationRule
    ->getUuid()) {
    $this->fieldValidationRuleSet
      ->addFieldValidationRule($this->fieldValidationRule
      ->getConfiguration());
  }
  else {
    $this->fieldValidationRuleSet
      ->deleteFieldValidationRule($this->fieldValidationRule);
    $this->fieldValidationRuleSet
      ->addFieldValidationRule($this->fieldValidationRule
      ->getConfiguration());
  }
  $this->fieldValidationRuleSet
    ->save();
  $this
    ->messenger()
    ->addMessage($this
    ->t('The rule was successfully applied.'));
  $form_state
    ->setRedirectUrl($this->fieldValidationRuleSet
    ->toUrl('edit-form'));
}