class EntityBundleExistsConstraint
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/EntityBundleExistsConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\EntityBundleExistsConstraint
- 10 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/EntityBundleExistsConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\EntityBundleExistsConstraint
Checks if a bundle exists on a certain content entity type.
This differs from the `Bundle` constraint in that checks that the validated value is the *name of a bundle* of a particular entity type.
Attributes
#[Constraint(id: 'EntityBundleExists', label: new TranslatableMarkup('Entity bundle exists', [], [
'context' => 'Validation',
]), type: 'entity')]
Hierarchy
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\EntityBundleExistsConstraint extends \Symfony\Component\Validator\Constraint
Expanded class hierarchy of EntityBundleExistsConstraint
2 files declare their use of EntityBundleExistsConstraint
- ConstraintFactoryTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Validation/ ConstraintFactoryTest.php - EntityBundleExistsConstraintValidatorTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityBundleExistsConstraintValidatorTest.php
File
-
core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ EntityBundleExistsConstraint.php, line 18
Namespace
Drupal\Core\Validation\Plugin\Validation\ConstraintView source
class EntityBundleExistsConstraint extends SymfonyConstraint {
/**
* The entity type ID which should have the given bundle.
*
* This can contain variable values (e.g., `%parent`) that will be replaced.
*
* @var string
*
* @see \Drupal\Core\Config\Schema\TypeResolver::replaceVariable()
*/
public string $entityTypeId;
public function __construct(mixed $options = NULL, ?string $entityTypeId = NULL, public $message = "The '@bundle' bundle does not exist on the '@entity_type_id' entity type.", ?array $groups = NULL, mixed $payload = NULL) {
parent::__construct($options, $groups, $payload);
$this->entityTypeId = $entityTypeId ?? $this->entityTypeId;
}
/**
* {@inheritdoc}
*/
public function getDefaultOption() : ?string {
return 'entityTypeId';
}
/**
* {@inheritdoc}
*/
public function getRequiredOptions() : array {
return [
'entityTypeId',
];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| EntityBundleExistsConstraint::$entityTypeId | public | property | The entity type ID which should have the given bundle. |
| EntityBundleExistsConstraint::getDefaultOption | public | function | |
| EntityBundleExistsConstraint::getRequiredOptions | public | function | |
| EntityBundleExistsConstraint::__construct | public | function | #[HasNamedArguments] |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.