You are here

class BundleConstraint in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraint

Checks if a value is a valid entity type.

Plugin annotation


@Constraint(
  id = "Bundle",
  label = @Translation("Bundle", context = "Validation"),
  type = { "entity", "entity_reference" }
)

Hierarchy

  • class \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraint extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of BundleConstraint

1 file declares its use of BundleConstraint
EntityContextDefinition.php in core/lib/Drupal/Core/Plugin/Context/EntityContextDefinition.php

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraint.php, line 16

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint
View source
class BundleConstraint extends Constraint {

  /**
   * The default violation message.
   *
   * @var string
   */
  public $message = 'The entity must be of bundle %bundle.';

  /**
   * The bundle option.
   *
   * @var string|array
   */
  public $bundle;

  /**
   * Gets the bundle option as array.
   *
   * @return array
   */
  public function getBundleOption() {

    // Support passing the bundle as string, but force it to be an array.
    if (!is_array($this->bundle)) {
      $this->bundle = [
        $this->bundle,
      ];
    }
    return $this->bundle;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOption() {
    return 'bundle';
  }

  /**
   * {@inheritdoc}
   */
  public function getRequiredOptions() {
    return [
      'bundle',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BundleConstraint::$bundle public property The bundle option.
BundleConstraint::$message public property The default violation message.
BundleConstraint::getBundleOption public function Gets the bundle option as array.
BundleConstraint::getDefaultOption public function
BundleConstraint::getRequiredOptions public function