Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301360

UniqueFieldValueValidator does not work when used as a constraint for the Entity ID Field

$
0
0

Problem/Motivation

The UniqueFieldValueValidator does not work if the field which it is validating is also the field used for the Entity ID.

This is an edge-case and only appears when the Entity Type provides the ability for the user to specify what the ID of the Entity being created should be.

    if (isset($entity_id)) {
      $query->condition($id_key, $entity_id, '<>');
    }

    $value_taken = (bool) $query
      ->condition($field_name, $item->value)

In a normal use case where the validator is not being used to check against the Entity ID field, this code will work because it will find all Entities except the current one which have the value set. In other words it will check two different fields, the Entity ID field and the field that it is validating.

However in this edge-case those two conditions will both check for the Entity ID field and so effectively cancel each other out, meaning the query will always return no results, and so the validation will always pass even when it should fail.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 301360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>