class TestValidatedReferenceConstraintValidator

Same name in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\TestValidatedReferenceConstraintValidator
  2. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\TestValidatedReferenceConstraintValidator
  3. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\TestValidatedReferenceConstraintValidator

Validates referenced entities.

Hierarchy

Expanded class hierarchy of TestValidatedReferenceConstraintValidator

File

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

Namespace

Drupal\entity_test\Plugin\Validation\Constraint
View source
class TestValidatedReferenceConstraintValidator extends ConstraintValidator {
    
    /**
     * {@inheritdoc}
     */
    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();
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
TestValidatedReferenceConstraintValidator::validate public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.