public function BundleConstraintValidator::validate in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator::validate()
File
- core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ BundleConstraintValidator.php, line 16
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, [
'%bundle' => implode(', ', $constraint
->getBundleOption()),
]);
}
}