function BundleConstraintValidator::validate

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator::validate()
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator::validate()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraintValidator::validate()

phpcs:ignore Drupal.Commenting.FunctionComment.VoidReturn

Return value

void

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php, line 19

Class

BundleConstraintValidator
Validates the Bundle constraint.

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint

Code

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()),
        ]);
    }
}

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