public function EntityTestCompositeConstraintValidator::validate in Zircon Profile 8.0
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::validate()
Checks if the passed value is valid.
Parameters
mixed $value The value that should be validated:
Constraint $constraint The constraint for the validation:
Overrides ConstraintValidatorInterface::validate
File
- core/modules/ system/ tests/ modules/ entity_test/ src/ Plugin/ Validation/ Constraint/ EntityTestCompositeConstraintValidator.php, line 28 
- Contains \Drupal\entity_test\Plugin\Validation\Constraint\EntityTestCompositeConstraintValidator.
Class
- EntityTestCompositeConstraintValidator
- Constraint validator for the EntityTestComposite constraint.
Namespace
Drupal\entity_test\Plugin\Validation\ConstraintCode
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();
  }
}