public function BundleConstraintValidator::validate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator::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/ Entity/ Plugin/ Validation/ Constraint/ BundleConstraintValidator.php, line 21 - Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator.
Class
- BundleConstraintValidator
- Validates the Bundle constraint.
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintCode
public function validate($entity, Constraint $constraint) {
if (!isset($entity)) {
return;
}
if (!in_array($entity
->bundle(), $constraint
->getBundleOption())) {
$this->context
->addViolation($constraint->message, array(
'%bundle' => implode(', ', $constraint
->getBundleOption()),
));
}
}