You are here

private function ContextFormBase::validateReactions in Context 8

Same name and namespace in other branches
  1. 8.4 modules/context_ui/src/Form/ContextFormBase.php \Drupal\context_ui\Form\ContextFormBase::validateReactions()

Validate the context reaction plugins configuration forms.

Parameters

array $form: The rendered form.

FormStateInterface $form_state: The current form state.

1 call to ContextFormBase::validateReactions()
ContextFormBase::validateForm in modules/context_ui/src/Form/ContextFormBase.php
Form validation handler.

File

modules/context_ui/src/Form/ContextFormBase.php, line 199

Class

ContextFormBase

Namespace

Drupal\context_ui\Form

Code

private function validateReactions(array &$form, FormStateInterface $form_state) {
  $reactions = $form_state
    ->getValue('reactions', []);

  // Loop trough each reaction and update the configuration values by
  // validating the reactions form.
  foreach ($reactions as $reaction_id => $configuration) {
    $reaction = $this->entity
      ->getReaction($reaction_id);
    $reaction_values = (new FormState())
      ->setValues($configuration);
    $reaction
      ->validateConfigurationForm($form, $reaction_values);
    if ($reaction_values
      ->hasAnyErrors()) {

      // In case of errors, copy them back from the dummy FormState to the
      // master form.
      foreach ($reaction_values
        ->getErrors() as $element => $error) {
        $form_state
          ->setErrorByName("reactions][{$reaction_id}][{$element}", $error);
      }
    }
  }
}