EntityTypeConstraint.php
Same filename and directory in other branches
- 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
- 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
- 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
- 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintFile
-
core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ EntityTypeConstraint.php
View source
<?php
namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Validation\Attribute\Constraint;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint as SymfonyConstraint;
/**
* Checks if a value is a valid entity type.
*/
class EntityTypeConstraint extends SymfonyConstraint {
/**
* The entity type option.
*
* @var string
*/
public $type;
public function __construct(mixed $options = NULL, ?string $type = NULL, public $message = 'The entity must be of type %type.', ?array $groups = NULL, mixed $payload = NULL) {
parent::__construct($options, $groups, $payload);
$this->type = $type ?? $this->type;
}
/**
* {@inheritdoc}
*/
public function getDefaultOption() : ?string {
return 'type';
}
/**
* {@inheritdoc}
*/
public function getRequiredOptions() : array {
return [
'type',
];
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| EntityTypeConstraint | Checks if a value is a valid entity type. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.