You are here

protected function RecursiveContextualValidator::validateConstraints in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php \Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validateConstraints()

Validates a node's value against all constraints in the given group.

Parameters

mixed $value: The validated value.

string $cache_key: The cache key used internally to ensure we don't validate the same constraint twice.

\Symfony\Component\Validator\Constraint[] $constraints: The constraints which should be ensured for the given value.

1 call to RecursiveContextualValidator::validateConstraints()
RecursiveContextualValidator::validateNode in core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php
Validates a Typed Data node in the validation tree.

File

core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php, line 178

Class

RecursiveContextualValidator
Defines a recursive contextual validator for Typed Data.

Namespace

Drupal\Core\TypedData\Validation

Code

protected function validateConstraints($value, $cache_key, $constraints) {
  foreach ($constraints as $constraint) {

    // Prevent duplicate validation of constraints, in the case
    // that constraints belong to multiple validated groups
    if (isset($cache_key)) {
      $constraint_hash = spl_object_hash($constraint);
      if ($this->context
        ->isConstraintValidated($cache_key, $constraint_hash)) {
        continue;
      }
      $this->context
        ->markConstraintAsValidated($cache_key, $constraint_hash);
    }
    $this->context
      ->setConstraint($constraint);
    $validator = $this->constraintValidatorFactory
      ->getInstance($constraint);
    $validator
      ->initialize($this->context);
    $validator
      ->validate($value, $constraint);
  }
}