class EntityTestCompositeConstraintValidator in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/EntityTestCompositeConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\EntityTestCompositeConstraintValidator
- 9 core/modules/system/tests/modules/entity_test/src/Plugin/Validation/Constraint/EntityTestCompositeConstraintValidator.php \Drupal\entity_test\Plugin\Validation\Constraint\EntityTestCompositeConstraintValidator
Constraint validator for the EntityTestComposite constraint.
Hierarchy
- class \Drupal\entity_test\Plugin\Validation\Constraint\EntityTestCompositeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of EntityTestCompositeConstraintValidator
File
- core/
modules/ system/ tests/ modules/ entity_test/ src/ Plugin/ Validation/ Constraint/ EntityTestCompositeConstraintValidator.php, line 11
Namespace
Drupal\entity_test\Plugin\Validation\ConstraintView source
class EntityTestCompositeConstraintValidator extends ConstraintValidator {
/**
* Validator 2.5 and upwards compatible execution context.
*
* @var \Symfony\Component\Validator\Context\ExecutionContextInterface
*/
protected $context;
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) {
if ($entity->name->value === 'test' && $entity->type->value === 'test2') {
$this->context
->buildViolation($constraint->message)
->atPath('type')
->addViolation();
}
if ($entity->name->value === 'failure-field-name') {
$this->context
->buildViolation('Name field violation')
->atPath('name')
->addViolation();
}
elseif ($entity->name->value === 'failure-field-type') {
$this->context
->buildViolation('Type field violation')
->atPath('type')
->addViolation();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityTestCompositeConstraintValidator:: |
protected | property | Validator 2.5 and upwards compatible execution context. | |
EntityTestCompositeConstraintValidator:: |
public | function |