TestValidatedReferenceConstraintValidator.php
Same filename in other branches
- 9 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php
- 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php
- 10 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/TestValidatedReferenceConstraintValidator.php
Namespace
Drupal\entity_test\Plugin\Validation\ConstraintFile
-
core/
modules/ system/ tests/ modules/ entity_test/ src/ Plugin/ Validation/ Constraint/ TestValidatedReferenceConstraintValidator.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_test\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates referenced entities.
*/
class TestValidatedReferenceConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) : void {
if (!isset($items)) {
return;
}
foreach ($items as $item) {
$violations = $item->entity
->validate();
if ($violations->count()) {
// Add the reason for the validation failure to the current context.
$this->context
->buildViolation($constraint->message)
->addViolation();
}
}
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
TestValidatedReferenceConstraintValidator | Validates referenced entities. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.