Problem/Motivation

With the Drupal core autocomplete (Tags style) widget, a referenced entity shows its ID. Autocomplete Deluxe hides it, which is nicer to read, but the ID is sometimes the only thing that tells two entities apart — two taxonomy terms with the same word, or the same word with and without accents on a multilingual site — and it is also useful when the referenced entity has to be filtered by ID somewhere else.

Steps to reproduce

  1. Add two entities with the same label to the vocabulary or content type being referenced.
  2. Reference them with a field using the Autocomplete Deluxe widget.
  3. The two tags read the same, and the suggestion list shows the same word twice.

Proposed resolution

Add a widget setting, Show the entity ID, which is off by default so nothing changes for the sites that are happy with the clean label. When it is on, the tag and the suggestion list keep the ID that the stored value already carries.

Two fields on the same form, one showing the entity ID in the tags and one without it

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ➖ Automated unit testing coverage
  • ➖ Automated functional testing coverage
  • ➖ UX/UI designer responsibilities
  • ➖ Readability
  • ➖ Accessibility
  • ➖ Performance
  • ➖ Security
  • ➖ Developer Documentation
  • ➖ User Guide Documentation
  • ➖ Reviewed by human
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

User interface changes

  • A new Show the entity ID checkbox in the widget settings, off by default.

API changes

  • N/A

Data model changes

  • The widget carries one more setting, show_entity_id, which defaults to FALSE.

Release notes snippet

  • The Autocomplete Deluxe widget can now show the entity ID beside the label, which tells two entities with the same name apart.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Shenron_segamag created an issue. See original summary.

shenron_segamag’s picture

Issue summary: View changes
emilie.viau’s picture

Category: Feature request » Bug report
StatusFileSize
new45.91 KB

I suggest to report as a bug rather than a feature request. Reason : when you work in multilingual websites, like in French, words in Taxonomy may have different forms with and without accents. For example, the word "léipoa" and leipoa can be both with or without accent. In such case, Drupal ask us to specify the ID, which is possible with the native autocomplete, but not with Autocomplete Deluxe. In fact, we have the possibility to specify the ID temporarily, but as soon as we save the page and open it again, the ID has disappeared and Drupal display an error.

rajab natshah’s picture

Issue summary: View changes

alesbencina made their first commit to this issue’s fork.

There's another PR, that needs to be reviewed https://git.drupalcode.org/project/autocomplete_deluxe/-/merge_requests/10

kevinvb made their first commit to this issue’s fork.

kevinvb’s picture

Added extra commit so not only the entered items are displaying the entity ID but also the autocomplete results display their ID.
We encountered this issue because we had a project containing multiple nodes with the same title making it almost impossible to know which item corresponds with the desired node.

kevinvb’s picture

Status: Active » Needs review

rajab natshah’s picture

Version: 2.0.x-dev » 2.1.x-dev
Assigned: Unassigned » rajab natshah
Issue summary: View changes
StatusFileSize
new75.09 KB

Thank you, Vanessa for reporting, Emilie for the multilingual case, and Ales and Kevin for the work on the earlier merge request.

Kept it as an option rather than always on, since most sites picked this widget for the clean label. The new merge request adds a Show the entity ID checkbox to the widget settings, off by default.

Tested on Drupal 11.4 with two fields on one form, one with the setting on and one off: the tags read Test (1) and Alpha (beta) (6) with it on and stay clean with it off, the suggestion list follows the same rule, and saving stores the right term IDs and creates no new terms.

One field showing the entity ID and one without it

To review, test, then merge.

  • rajab natshah committed 8a51a85d on 2.1.x
    feat: #3181219 Add a widget setting to show the entity ID in the tag
    
rajab natshah’s picture

Status: Needs review » Fixed

This is already in. The work was committed to 2.1.x on 29 August as "Add a widget setting to show the entity ID in the tag", and it is currently the tip of the branch.

Everything is there: the show_entity_id setting with its checkbox, the line in the widget summary, the handling in the suggestions and in the tags, and a feature file covering it. The issue had simply been left at needs review, so I am marking it fixed to match what the branch actually holds.

One loose end worth tidying separately. There is still an open merge request against 2.0.x for this issue, from before the work moved to 2.1.x. It is superseded now and can be closed whenever you are happy to.

Prepared with AI assistance (Claude), reviewed and driven by the maintainer.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.