BundleConstraintValidator.php 618 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
  3. use Symfony\Component\Validator\Constraint;
  4. use Symfony\Component\Validator\ConstraintValidator;
  5. /**
  6. * Validates the Bundle constraint.
  7. */
  8. class BundleConstraintValidator extends ConstraintValidator {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function validate($entity, Constraint $constraint) {
  13. if (!isset($entity)) {
  14. return;
  15. }
  16. if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
  17. $this->context->addViolation($constraint->message, ['%bundle' => implode(', ', $constraint->getBundleOption())]);
  18. }
  19. }
  20. }