Problem/Motivation

When changing the label of a result to something completely different, or anytime a search result returned by Drupal does not contain the original search term, the result is not being shown in the dropdown, even though it's present in the entity autocomplete JSON response.

Steps to reproduce

One way to reproduce this is to implement hook_tagify_autocomplete_match_alter() like this:

/**
 * Implements hook_tagify_autocomplete_match_alter().
 */
function my_module_tagify_autocomplete_match_alter(?string &$label, ?string &$info_label, array $context): void
{
    $label = 'Test';
}

Search for the original title of an entity. It should appear in the search results with 'Test' as label, but it doesn't.

Issue fork tagify-3458377

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

DieterHolvoet created an issue. See original summary.

dieterholvoet’s picture

This would be fixed if we could somehow not let Tagify filter the results. So only Drupal does filtering, Tagify just shows the list of results that's returned by Drupal.

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

gxleano’s picture

Status: Active » Needs review
gxleano’s picture

The same logic will be added to the Tagify User List module.

dieterholvoet’s picture

Status: Needs review » Needs work

That doesn't fix the problem in my use case. I should've been more clear, I'll explain. I have an Artist content type with an 'Alternative spellings' field. I wrote a custom entity reference selection handler that doesn't only search the title field, but also the alternative spellings field. So imagine there's a 'Foo' artist with 'Bar' in its alternative spellings. Now, when I search for 'Bar', the autocomplete endpoint returns the following data:

[
  {
    "entity_id": 15190,
    "entity_title": "Foo",
    "label": "Foo",
    "info_label": "",
    "editable": false
  },
  {
    "entity_id": 9133,
    "entity_title": "Barox",
    "label": "Barox",
    "info_label": "",
    "editable": false
  },
  {
    "entity_id": 5028,
    "entity_title": "Barker",
    "label": "Barker",
    "info_label": "",
    "editable": false
  },
  {
    "entity_id": 7076,
    "entity_title": "Baraka",
    "label": "Baraka",
    "info_label": "",
    "editable": false
  }
]

but the first result isn't shown in the widget. Isn't it possible to disable Tagify filtering the results? I don't see why that's necessary, since the backend does the filtering.

gxleano’s picture

In my view, there are two distinct aspects here:

Bug Fix: The issue of matching results not appearing when a label is modified. This has been addressed in the current update. It appears that the label alteration feature wasn't functioning as expected, and the new logic now resolves this issue.

New Feature: The addition of alternative spellings or synonyms configuration for the Tagify widget. We can introduce a new configuration option in the widget that allows you to define alternative spellings or synonyms using tokens and specify the field that contains these variations.

So, I would create a new issue where add the requirements about the new feature.

gxleano’s picture

Status: Needs work » Needs review
dieterholvoet’s picture

New Feature: The addition of alternative spellings or synonyms configuration for the Tagify widget. We can introduce a new configuration option in the widget that allows you to define alternative spellings or synonyms using tokens and specify the field that contains these variations.

No, this is not what I asked. The alternative spellings feature is something I have in my own site, something that's completely handled within a custom entity reference selection handler. The only problem is that Tagify doesn't display a suggestion that's returned by Drupal if the search term is not contained in the suggestion. You can see that in the example JSON I embedded in my previous comment.

I just had a look myself and found an easy fix to make sure no results returned by Drupal are ever excluded from the Tagify dropdown.

dieterholvoet’s picture

Title: Matching results are not shown when label is changed » Matching results are not shown if they don't contain the search term
Issue summary: View changes

I updated the issue title and description to be more clear.

gxleano’s picture

Understood, I will take a look into your changes.

Thanks!

gxleano’s picture

I've been testing the MR and it's working as expecting.

It will be included in 1.2.31 release.

gxleano’s picture

Status: Needs review » Fixed
gxleano’s picture

Status: Fixed » Closed (fixed)