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

Add duplicate term names prevention as a vocabulary option

$
0
0

Posted by xjm

Problem/Motivation

(From #1050466: The taxonomy index should be maintained in a node hook, not a field hook.)

  • If a node has multiple taxonomy autocomplete fields that use the same vocabulary and the user enters the same value in two fields, the term will be duplicated.

Example scenario

This is not just a weird edge case. Consider:

  1. You have a "University" vocabulary.
  2. You allow users to enter their undergraduate school in one field, and their graduate school in another.
  3. The user enters "University of Texas" in both fields.
  4. When the node is saved, there will be two different terms named "University of Texas."

Proposed resolution

  • Check for existing records with the same name in the same vocabulary before creating new terms.

Remaining tasks

  • It's been suggested that the query used in taxonomy_field_presave()to check for existing terms could lead to race conditions:
    +++ b/core/modules/taxonomy/taxonomy.moduleundefined
    @@ -1710,6 +1710,15 @@ function taxonomy_rdf_mapping() {
    +      // Avoid duplicating tags within the same vocabulary.
    +      $tid = db_query_range("SELECT tid FROM {taxonomy_term_data} WHERE name = :name AND vid = :vid", 0, 1, array(
    +        ':name' => trim($item['name']),
    +        ':vid' => $item['vid'],
    +      ))->fetchField();
    +      if (!empty($tid)) {
    +        $items[$delta]['tid'] = $tid;
    +        continue;
    +      }

    See #1050466-34: The taxonomy index should be maintained in a node hook, not a field hook for some proposed solutions.

User interface changes

  • None.

API changes

  • None.

Viewing all articles
Browse latest Browse all 299773

Latest Images

Trending Articles



Latest Images

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