BundleConstraintValidator.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint

File

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

View source
<?php

namespace Drupal\Core\Entity\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Validates the Bundle constraint.
 */
class BundleConstraintValidator extends ConstraintValidator {
    
    /**
     * {@inheritdoc}
     *
     * phpcs:ignore Drupal.Commenting.FunctionComment.VoidReturn
     * @return void
     */
    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()),
            ]);
        }
    }

}

Classes

Title Deprecated Summary
BundleConstraintValidator Validates the Bundle constraint.

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