class UniqueFieldConstraint

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldConstraint
  2. 10 core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldConstraint
  3. 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldConstraint

Checks if an entity field has a unique value.

Plugin annotation


@Constraint(
  id = "UniqueField",
  label = @Translation("Unique field constraint", context = "Validation"),
)

Hierarchy

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

Expanded class hierarchy of UniqueFieldConstraint

4 files declare their use of UniqueFieldConstraint
FeedTitleConstraint.php in core/modules/aggregator/src/Plugin/Validation/Constraint/FeedTitleConstraint.php
FeedUrlConstraint.php in core/modules/aggregator/src/Plugin/Validation/Constraint/FeedUrlConstraint.php
UserMailUnique.php in core/modules/user/src/Plugin/Validation/Constraint/UserMailUnique.php
UserNameUnique.php in core/modules/user/src/Plugin/Validation/Constraint/UserNameUnique.php

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldConstraint.php, line 15

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint
View source
class UniqueFieldConstraint extends Constraint {
    public $message = 'A @entity_type with @field_name %value already exists.';
    
    /**
     * {@inheritdoc}
     */
    public function validatedBy() {
        return '\\Drupal\\Core\\Validation\\Plugin\\Validation\\Constraint\\UniqueFieldValueValidator';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
UniqueFieldConstraint::$message public property 4
UniqueFieldConstraint::validatedBy public function

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