Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This problem occurs when a content type has multiple tagging fields using the same vocabulary. In such case, users can enter the same term in different fields which leads to non-unique tagging terms.
Comments
Comment #1
cluster4 CreditAttribution: cluster4 commentedI'm not used to the patching workflow of drupal. So here comes some raw code that can be considered as a quick fix for the described problem.
In "taxonomy.module" jump to the taxonomy_field_presave() function and add the following code to the top of the foreach loop:
Comment #2
sunWe need a much more clear and concise problem description here. Including clean steps to reproduce.
Comment #3
mr.baileysConfirmed this as a bug, steps to reproduce:
Expected outcome: term is created once, and both term reference fields reference that term.
Actual outcome: term is created twice, and both term reference fields refer to a separate term.
Reason seems to be that taxonomy_autocomplete_validate() uses taxonomy_term_load_multiple(), which caches the result. During the first iteration the term does not exist and is created, during the second iteration, taxonomy_term_load_multiple() still considers the term not to exist (cached), even though it was just created.
I can't really think of a valid use case for having 2 taxonomy reference fields (referencing the same vocabulary) on the same content type though, so downgrading this to a minor bug.
One solution might be to start using EntityFieldQuery to fetch the tids to load with taxonomy_term_load_multiple() instead of relying on the deprecated $conditions argument.
Comment #4
fangel CreditAttribution: fangel commentedmr.baileys: Isn't the problem more that the exist-check is done by
taxonomy_autocomplete_validate
, but the term-creation is done bytaxonomy_field_presave
, not that the results fromtaxonomy_term_load_multiple
is cached?So first both autocomplete-fields are element-validated, which sets them as "need to be created", and when the field is then saved, no checking is done to see if the term exists, so both terms are created.
Comment #5
xjmOops, didn't find this before I opened #1343822: Autocreated taxonomy terms duplicated if they are added to multiple fields, which itself was split off from #1050466: The taxonomy index should be maintained in a node hook, not a field hook. There's a patch there, though, so marking this issue duplicate.