class EntityHasFieldConstraint
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
- 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
- 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
- 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
Checks if a value is an entity that has a specific field.
Attributes
#[Constraint(id: 'EntityHasField', label: new TranslatableMarkup('Entity has field', [], [
'context' => 'Validation',
]), type: [
'entity',
])]
Hierarchy
- class \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint extends \Symfony\Component\Validator\Constraint
Expanded class hierarchy of EntityHasFieldConstraint
1 file declares its use of EntityHasFieldConstraint
- ConstraintFactoryTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Validation/ ConstraintFactoryTest.php
File
-
core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ EntityHasFieldConstraint.php, line 13
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintView source
class EntityHasFieldConstraint extends SymfonyConstraint {
/**
* The field name option.
*
* @var string
*/
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
public $field_name;
public function __construct(mixed $options = NULL, ?string $field_name = NULL, public $message = 'The entity must have the %field_name field.', public $notFieldableMessage = 'The entity does not support fields.', ?array $groups = NULL, mixed $payload = NULL) {
parent::__construct($options, $groups, $payload);
$this->field_name = $field_name ?? $this->field_name;
}
/**
* {@inheritdoc}
*/
public function getDefaultOption() : ?string {
return 'field_name';
}
/**
* {@inheritdoc}
*/
public function getRequiredOptions() : array {
return (array) $this->getDefaultOption();
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| EntityHasFieldConstraint::$field_name | public | property | The field name option. |
| EntityHasFieldConstraint::getDefaultOption | public | function | |
| EntityHasFieldConstraint::getRequiredOptions | public | function | |
| EntityHasFieldConstraint::__construct | public | function | #[HasNamedArguments] |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.