public function RecursiveContextualValidator::validatePropertyValue in Zircon Profile 8.0
Same name in this branch
- 8.0 vendor/symfony/validator/Validator/RecursiveContextualValidator.php \Symfony\Component\Validator\Validator\RecursiveContextualValidator::validatePropertyValue()
- 8.0 core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php \Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validatePropertyValue()
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php \Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validatePropertyValue()
Validates a value against the constraints specified for an object's property.
Parameters
object|string $objectOrClass The object or its class name:
string $propertyName The name of the property:
mixed $value The value to validate against the: property's constraints
array|null $groups The validation groups to validate. If: none is given, "Default" is assumed
Return value
ContextualValidatorInterface This validator
Overrides ContextualValidatorInterface::validatePropertyValue
File
- core/
lib/ Drupal/ Core/ TypedData/ Validation/ RecursiveContextualValidator.php, line 223 - Contains \Drupal\Core\TypedData\Validation\RecursiveContextualValidator.
Class
- RecursiveContextualValidator
- Defines a recursive contextual validator for Typed Data.
Namespace
Drupal\Core\TypedData\ValidationCode
public function validatePropertyValue($object, $property_name, $value, $groups = NULL) {
if (!is_object($object)) {
throw new \InvalidArgumentException('Passing class name is not supported.');
}
elseif (!$object instanceof TypedDataInterface) {
throw new \InvalidArgumentException('The passed in object has to be typed data.');
}
elseif (!$object instanceof ListInterface && !$object instanceof ComplexDataInterface) {
throw new \InvalidArgumentException('Passed data does not contain properties.');
}
$data = $object
->get($property_name);
$metadata = $this->metadataFactory
->getMetadataFor($data);
$constraints = $metadata
->findConstraints(Constraint::DEFAULT_GROUP);
return $this
->validate($value, $constraints, $groups, TRUE);
}