class BundleConstraintValidator

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator
  3. 10 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) : void {
        if (!isset($entity)) {
            return;
        }
        if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
            $this->context
                ->addViolation($constraint->message, [
                '%bundle' => implode(', ', $constraint->getBundleOption()),
            ]);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
BundleConstraintValidator::validate public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.