Entity autocomplete fails to create terms if term exists in other vocabulary

Created on 5 November 2024, about 2 months ago

Problem/Motivation

If I use "Autocomplete (Tags with selectize.js)" on:

Entity reference (Taxonomy Term) field
"Create referenced entities if they don't already exist" enabled
One vocabulary selected

selectize works perfectly UNLESS I 'Add' a term that matches one that already exists within another vocabulary .

Then if I try and save the node it then fails with an error :

This entity (taxonomy_term: 124) cannot be referenced.

Where term 124 is the matching term in the other vocabulary. (Not the vocabulary set for the field).

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom mistergroove

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mistergroove
  • 🇬🇧United Kingdom mistergroove

    Comparing validateEntityAutocomplete in Drupal\Core\Entity\Element\EntityAutocomplete and Drupal\selectize\Element\SelectizeEntityAutocomplete it seems the issue is the options are set differently now :

    $options = $element['#selection_settings'] + [
      'target_type' => $element['#target_type'],
      'handler' => $element['#selection_handler'],
    ];

    Drupal\Core\Entity\Element\EntityAutocomplete

    $options = [
      'target_type' => $element['#target_type'],
      'handler' => $element['#selection_handler'],
      'handler_settings' => $element['#selection_settings'],
    ];

    Drupal\selectize\Element\SelectizeEntityAutocomplete

    Changing it the selectize one to match seems to solve the issue.

  • 🇬🇧United Kingdom mistergroove

    I've made a patch which addresses this issue and the drag and drop issue in https://www.drupal.org/project/selectize/issues/3458652 📌 Drag and drop no longer works Active for testing.

Production build 0.71.5 2024