Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

The UniqueFieldValueValidator provides a constraint that can be added to a field to ensure that all values in the field are unique to that entity.

Drupal core uses this constraint for the User's name and mail fields.

Prior to 10.2.0 the validator only supported single-value fields and would not detect all duplicates for fields with more than one value. The first entry in the field would be validated against the first entry in all other entities, but subsequent entries would not be validated for uniqueness, whether against other entities or within the entity itself. Additionally, only simple field types such as plaintext fields would be validated, while entity reference and composite fields would not.

From 10.2.0 the validator will mark entities with duplicates in multi-value fields as invalid, regardless of whether the duplicates occur in other entities or within the validating entity. Additionally, the field's main property will be used for validation, thus providing validation for e.g. Link fields whose main property is the Link URL.

Future edits of content implementing UniqueFieldValueValidator will require removing duplicate values.

If the original behavior of the validator was used deliberately, e.g. for designating only the first value in a multivalue field as a "key," then the constraint will need to be removed from the field and a new custom constraint implemented. See Defining Constraints for more information.

Impacts: 
Site builders, administrators, editors
Module developers