public function ComplexDataConstraintValidator::validate in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ComplexDataConstraintValidator.php \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraintValidator::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/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ ComplexDataConstraintValidator.php, line 27 - Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraintValidator.
Class
- ComplexDataConstraintValidator
- Validates complex data.
Namespace
Drupal\Core\Validation\Plugin\Validation\ConstraintCode
public function validate($data, Constraint $constraint) {
// If un-wrapped data has been passed, fetch the typed data object first.
if (!$data instanceof TypedDataInterface) {
$data = $this
->getTypedData();
}
if (!$data instanceof ComplexDataInterface) {
throw new UnexpectedTypeException($data, 'ComplexData');
}
foreach ($constraint->properties as $name => $constraints) {
$this->context
->getValidator()
->inContext($this->context)
->validate($data
->get($name), $constraints, NULL, FALSE);
}
}