You are here

public function EditExpressionForm::validateForm in Rules 8.3

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/EditExpressionForm.php, line 107

Class

EditExpressionForm
UI form to edit an expression like a condition or action in a rule.

Namespace

Drupal\rules\Form

Code

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

  // Ensure the object properties are initialized, see
  // https://www.drupal.org/node/2669032.
  $this->rulesUiHandler = $form_state
    ->get('rules_ui_handler');
  $this->component = is_object($form_state
    ->get('component')) ? $form_state
    ->get('component') : $this->rulesUiHandler
    ->getComponent();
  $this->uuid = $form_state
    ->get('uuid');
  $this->rulesUiHandler
    ->validateLock($form, $form_state);

  // @todo This ignores ExpressionFormInterface::validateForm().
  $component = $this
    ->buildComponent($form, $form_state);
  $violations = $component
    ->checkIntegrity();

  // Only show the violations caused by the edited expression.
  foreach ($violations
    ->getFor($this->uuid) as $violation) {
    $form_state
      ->setError($form, $violation
      ->getMessage());
  }
}