You are here

class BundleConstraintValidator in Drupal 9

Same name and namespace in other branches
  1. 8 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\Constraint
View 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