class EntityHasFieldConstraint

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityHasFieldConstraint
  3. 10 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.

Hierarchy

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

Expanded class hierarchy of EntityHasFieldConstraint

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityHasFieldConstraint.php, line 12

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint
View source
class EntityHasFieldConstraint extends SymfonyConstraint {
    
    /**
     * The default violation message.
     *
     * @var string
     */
    public $message = 'The entity must have the %field_name field.';
    
    /**
     * The violation message for non-fieldable entities.
     *
     * @var string
     */
    public $notFieldableMessage = 'The entity does not support fields.';
    
    /**
     * The field name option.
     *
     * @var string
     */
    // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
    public $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
EntityHasFieldConstraint::$message public property The default violation message.
EntityHasFieldConstraint::$notFieldableMessage public property The violation message for non-fieldable entities.
EntityHasFieldConstraint::getDefaultOption public function
EntityHasFieldConstraint::getRequiredOptions public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.