You are here

public function TestValidatedReferenceConstraintValidator::validate in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\TestValidatedReferenceConstraintValidator::validate()
  2. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\TestValidatedReferenceConstraintValidator::validate()

File

core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php, line 16

Class

TestValidatedReferenceConstraintValidator
Validates referenced entities.

Namespace

Drupal\entity_test\Plugin\Validation\Constraint

Code

public function validate($items, Constraint $constraint) {
  if (!isset($items)) {
    return;
  }
  foreach ($items as $item) {
    $violations = $item->entity
      ->validate();
    foreach ($violations as $violation) {

      // Add the reason for the validation failure to the current context.
      $this->context
        ->buildViolation($constraint->message)
        ->addViolation();
    }
  }
}