Matching results are not shown when label is changed

Created on 1 July 2024, 9 months ago

Problem/Motivation

When changing the label of a result to something completely different, the result is no longer being shown in the dropdown, even though it's present in the entity autocomplete JSON response.

Steps to reproduce

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.

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

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

Merge Requests

Comments & Activities

  • Issue created by @dieterholvoet
  • 🇧🇪Belgium dieterholvoet Brussels

    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.

  • First commit to issue fork.
  • 🇪🇸Spain gxleano Cáceres

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

  • 🇧🇪Belgium dieterholvoet Brussels

    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.

  • 🇪🇸Spain gxleano Cáceres

    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.

  • 🇧🇪Belgium dieterholvoet Brussels

    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.

  • 🇧🇪Belgium dieterholvoet Brussels

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

  • Pipeline finished with Success
    about 2 months ago
    Total: 401s
    #400893
  • 🇪🇸Spain gxleano Cáceres

    Understood, I will take a look into your changes.

    Thanks!

  • 🇪🇸Spain gxleano Cáceres

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

    It will be included in 1.2.31 release.

Production build 0.71.5 2024