Checks if the passed value is valid.
@api
mixed $value The value that should be validated:
Constraint $constraint The constraint for the validation:
Overrides ConstraintValidatorInterface::validate
public function validate($value, Constraint $constraint) {
if (!isset($value)) {
return;
}
if (!$value instanceof ComplexDataInterface) {
throw new UnexpectedTypeException($value, 'ComplexData');
}
$group = $this->context
->getGroup();
foreach ($constraint->properties as $name => $constraints) {
$property = $value
->get($name);
$is_container = $property instanceof ComplexDataInterface || $property instanceof ListInterface;
if (!$is_container) {
$property = $property
->getValue();
}
elseif ($property
->isEmpty()) {
// @see \Drupal\Core\TypedData\Validation\PropertyContainerMetadata::accept();
$property = NULL;
}
$this->context
->validateValue($property, $constraints, $name, $group);
}
}