class BundleConstraintValidator in Drupal 8
Same name and namespace in other branches
- 9 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BundleConstraintValidator:: |
public | function | Checks if the passed value is valid. |