class EntityHasFieldConstraintValidator
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraintValidator
- 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraintValidator
- 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraintValidator
Validates the EntityHasField constraint.
Hierarchy
- class \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of EntityHasFieldConstraintValidator
File
-
core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ EntityHasFieldConstraintValidator.php, line 12
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintView source
class EntityHasFieldConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) {
if (!isset($entity)) {
return;
}
/** @var \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint $constraint */
if (!$entity instanceof FieldableEntityInterface) {
$this->context
->addViolation($constraint->notFieldableMessage);
return;
}
if (!$entity->hasField($constraint->field_name)) {
$this->context
->addViolation($constraint->message, [
'%field_name' => $constraint->field_name,
]);
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.