class BundleConstraintValidator
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator
- 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator
- 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator
Validates the Bundle constraint.
Hierarchy
- class \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of BundleConstraintValidator
File
-
core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ BundleConstraintValidator.php, line 11
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintView source
class BundleConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
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()),
]);
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.