3 namespace Drupal\entity_test\Plugin\Validation\Constraint;
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
9 * Constraint validator for the EntityTestComposite constraint.
11 class EntityTestCompositeConstraintValidator extends ConstraintValidator {
14 * Validator 2.5 and upwards compatible execution context.
16 * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
23 public function validate($entity, Constraint $constraint) {
25 if ($entity->name->value === 'test' && $entity->type->value === 'test2') {
26 $this->context->buildViolation($constraint->message)
30 if ($entity->name->value === 'failure-field-name') {
31 $this->context->buildViolation('Name field violation')
35 elseif ($entity->name->value === 'failure-field-type') {
36 $this->context->buildViolation('Type field violation')