You are here

public function FieldValidationRuleFormBase::validateForm in Field Validation 8

Form validation 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 FormBase::validateForm

File

src/Form/FieldValidationRuleFormBase.php, line 234

Class

FieldValidationRuleFormBase
Provides a base form for FieldValidationRule.

Namespace

Drupal\field_validation\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // The fieldValidationRule configuration is stored in the 'data' key in the form,
  // pass that through for validation.
  $data = $form_state
    ->getValue('data');
  if (empty($data)) {
    $data = [];
  }
  $field_validation_rule_data = (new FormState())
    ->setValues($data);
  $this->fieldValidationRule
    ->validateConfigurationForm($form, $field_validation_rule_data);

  // Update the original form values.
  $form_state
    ->setValue('data', $field_validation_rule_data
    ->getValues());
}