Add the ability to show extra metadata in results

Created on 6 January 2024, 6 months ago
Updated 4 April 2024, 3 months ago

Problem/Motivation

It would be useful to add the ability to show extra metadata to the right of entity labels, just like the entity ID can be shown to the left of the label. Some use cases:

  • I have an entity reference field allowing to reference nodes of multiple different types. I often have entities with the same exact title, but with different labels. Currently, it's impossible to tell the difference between the two, unless I enable showing entity ID's in results.
  • I have an entity reference field allowing to reference events. Events have an entity reference field referencing a taxonomy vocabulary 'event type' (e.g. Club night, Concert). It would be useful to show that value next to the entity label.

Proposed resolution

We could show it as a kind of tag inside the tag, on the right side of the label. Just like the user widget shows the user picture on the left side of the label, or the normal widget can show the entity ID on the left of the label.

Remaining tasks

  • Create documentation page explaining how it is working
Feature request
Status

Fixed

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

    It would be even better if we didn't have this only if the field allows multiple bundles, and if we could choose the field whose value is displayed at that position. Example: a field allows referencing events. Events have an entity reference field referencing a taxonomy vocabulary 'event type' (e.g. Club night, Concert). It would be useful to show that value next to the entity label. Let me know what you think.

  • 🇧🇪Belgium DieterHolvoet Brussels

    I updated the issue title/description. @gxleano can you let me know if you think this kind of feature would be useful? Just so I know if it's worth it for me to spend time developing this.

  • 🇪🇸Spain gxleano Cáceres

    Hi @DieterHolvoet!

    Thanks for always giving feedback and suggesting new ideas for the module.

    In this case, if we add the ability to show extra information (bundle type for instances) on the tag, it might make the tag too full and not very user-friendly. I'm not sure if that's the best user experience.

    Another option could be to show the bundle type when you hover over the tag. This way, we wouldn't add more stuff to the tag, and users could see the bundle type when they hover. I found a nice example here: https://atomiks.github.io/tippyjs/#placements. We could try to implement something similar without needing an external source.

  • Status changed to Closed: won't fix 5 months ago
  • 🇪🇸Spain gxleano Cáceres

    Closing this issue because it has been inactive for almost a month.

    If this topic returns, a new issue will be created.

  • Status changed to Active 4 months ago
  • 🇧🇪Belgium DieterHolvoet Brussels

    I'm not sure if a hover tooltip would be a good alternative since the information wouldn't be immediately visible, and if you're using a touch device the information wouldn't be visible at all. I don't think the tag being too full would be a big concern. What exact information would be displayed would be configurable, so it's the user's choice how much they want to put in there.

    I really believe this would be a good improvement, I could use it on multiple entity reference fields in a project I'm working on almost daily. Entity labels are not unique identifiers, for me it happens regularly that multiple entities have the same title and if that happens, it becomes really hard to pick the right entity from the list. Adding contextual information would help a lot.

  • 🇪🇸Spain gxleano Cáceres

    @DieterHolvoet

    Let's try it and see how it is looking.

  • Assigned to sourabhsisodia_
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • Pipeline finished with Success
    3 months ago
    Total: 162s
    #125071
  • The applied changes looked likes the below image

  • 🇪🇸Spain gxleano Cáceres

    @sourabhsisodia_

    Thanks to start working on this.

    I've added some comments to the MR, I will take over of this.

    Moving the issue to Needs work.

  • Assigned to gxleano
  • Status changed to Needs work 3 months ago
  • 🇪🇸Spain gxleano Cáceres
  • 🇪🇸Spain gxleano Cáceres

    https://www.drupal.org/project/tagify/issues/3412898#comment-15507817 Add the ability to show extra metadata in results Needs work

    1. Metadata appears as undefined when the entity reference is a Taxonomy term.
    2. Metadata label doesn't appear when 'Include entity Id' option is not checked.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇪🇸Spain gxleano Cáceres

    ⚙️ Configuration

    🎬Demo

  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇪🇸Spain gxleano Cáceres
  • 🇧🇪Belgium DieterHolvoet Brussels

    Would be nice if we could configure what exact info is shown in the label, as described in the issue description. The best way seems to me to use a text field where you can use tokens to include certain field data. Should be fairly easy to implement, I can have a look at this if you want.

  • 🇪🇸Spain gxleano Cáceres

    Sure @DieterHolvoet

    Feel free to take over of this, as you already have clear the idea.

  • Hey @gxleano, your remarks and code changes looks great, learned a lot.

  • 🇧🇪Belgium DieterHolvoet Brussels

    About naming: we probably shouldn't call this 'entity label', since in Drupal context that usually means the title of the label. We also shouldn't use 'tag', since that's the whole feature of this module. What about 'info label'? Or any other ideas?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 169s
    #126612
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Canceled
    3 months ago
    Total: 95s
    #126625
  • Pipeline finished with Success
    3 months ago
    Total: 200s
    #126629
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Status changed to Needs work 3 months ago
  • 🇧🇪Belgium DieterHolvoet Brussels

    I renamed the 'entity label' terminology to 'info label' and I made the content of the tag dynamic. I started work on the user widget as well, but both still need some finishing touches and testing. Some use cases I already tried it out with:

    Referencing events and showing the dates

    Referencing music releases and showing the artists

  • Pipeline finished with Success
    3 months ago
    Total: 172s
    #126637
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 191s
    #126671
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 163s
    #126981
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Status changed to Needs review 3 months ago
  • 🇧🇪Belgium DieterHolvoet Brussels

    In the user widget, I made the info label the line that was previously hardcoded to the user email address. Now people can choose what to show there. There's an update hook that makes sure the email will stay displayed for existing websites.

    I think everything is ready now, let's start testing!

  • Pipeline finished with Success
    3 months ago
    Total: 166s
    #126984
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 177s
    #127044
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 214s
    #127852
  • 🇧🇪Belgium DieterHolvoet Brussels

    @gxleano I had to revert the changes you did in your commit 'Avoid to remove duplicated labels from different bundle', where you changed the tagify tag value from the label to the entity ID. It broke the functionality of automatically creating new entities inline: when pasting a word in the input field or typing an unknown title and pressing enter, the tag would show 'undefined'.

  • 🇪🇸Spain gxleano Cáceres

    @DieterHolvoet

    I'll work on this https://www.drupal.org/project/tagify/issues/3412898#comment-15513703 Add the ability to show extra metadata in results Needs work , because we need to have this modification/fix.

    If we don't have it, we won't be able to add a tag with same value/name and different vocabulary, for instance:

    Term 1 (Fruit)
    Term 1 (Vegetable)

    Tagify will detected as duplicated. So, the value would need to be the entity id (to be unique).

  • 🇪🇸Spain gxleano Cáceres

    On the other hand, regarding the use of tokens, I like the idea (don't get me wrong), but I would try to do this without depending on external modules.

    My idea would be to create a select element instead of a textfield, where list all the available fields/values on the entity which we are going to use the Tagify widget, then the user could select which value want to show in the info label.

    I will finish to check your code and do the rest of the modification.

    Thanks and good job @DieterHolvoet 💪🏼

  • Assigned to gxleano
  • Status changed to Needs work 3 months ago
  • 🇪🇸Spain gxleano Cáceres
  • 🇧🇪Belgium DieterHolvoet Brussels

    If we don't have it, we won't be able to add a tag with same value/name and different vocabulary.

    That's not a new issue though, right? That problem is not being introduced by this new feature? In that case I would create a new issue for that and discuss it further over there, just to keep this focused.

    On the other hand, regarding the use of tokens, I like the idea (don't get me wrong), but I would try to do this without depending on external modules.

    Tokens are part of Drupal core. There is a contrib module named Token, which provides extra tokens that Drupal core doesn't, but the whole token concept is a Drupal core thing. You're right about the UI part, the token_tree_link theme hook, being part of the contrib module. We could place a check around it to only render it when the module is installed, since it's completely optional. The Token module is the top installed, most popular Drupal module though, so it's probably installed on most sites. I do agree that we shouldn't add it as a dependency.

  • 🇧🇪Belgium DieterHolvoet Brussels

    My idea would be to create a select element instead of a textfield, where list all the available fields/values on the entity which we are going to use the Tagify widget, then the user could select which value want to show in the info label.

    I really wouldn't do this. It would be kind of reinventing the wheel: it would introduce a lot of extra logic and we would lose a lot of flexibility that the token system provides. Tokens are the de facto way to do this kind of thing across Drupal core and contrib.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇪🇸Spain gxleano Cáceres

    @DieterHolvoet

    https://www.drupal.org/project/tagify/issues/3412898#comment-15513703 Add the ability to show extra metadata in results Needs work

    Is already handled here https://www.drupal.org/project/tagify/issues/3435956 🐛 Tags with same value are considered duplicated Needs review

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 168s
    #128902
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Pipeline finished with Success
    3 months ago
    Total: 228s
    #128992
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇪🇸Spain gxleano Cáceres

    Added support for images to Info Label.

    Example:

    Country vocabulary with image field 'Flag'.

    Using the token: [term:field_flag:thumbnail:url]

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇪🇸Spain gxleano Cáceres
  • 🇧🇪Belgium DieterHolvoet Brussels

    After the latest updates the info tags seem to be missing right padding:

    When I inline edit the title of an already referenced entity, after pressing enter the change is discarded.

    I also feel like the left/right padding around the images is a little too much. How about 0.5rem on both sides, like this?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇪🇸Spain gxleano Cáceres

    Thanks to catch up @DieterHolvoet

    The fixes are already in place.

  • 🇧🇪Belgium DieterHolvoet Brussels

    The padding issues are fixed, thanks!

    When I inline edit the title of an already referenced entity, after pressing enter the change is discarded.

    Now the changes aren't discarded anymore after pressing enter, but they also aren't saved after submitting the form. Did it work like this before? Are you supposed to be able to change the titles of referenced entities in the Tagify widget? If so, this should be fixed.

  • 🇪🇸Spain gxleano Cáceres
  • 🇪🇸Spain gxleano Cáceres
  • 🇧🇪Belgium DieterHolvoet Brussels

    I had another idea: maybe we could improve the tagify_autocomplete_matches alter hook. Currently, it's not that useful since the entity object is not passed. Only the label strings are passed, but they generally don't contain enough information to make decisions.

    How about we add a tagify_autocomplete_match alter hook? We call it after $this->token->replacePlain() and we pass the $entity, $label (as reference, so we can change it) and $info_label (also as reference, so we can change it). If a hook implementation returns FALSE, the match is not included in the results.

    I can implement this if you want, just let me know if you think it's a good idea.

  • 🇪🇸Spain gxleano Cáceres

    Now the changes aren't discarded anymore after pressing enter, but they also aren't saved after submitting the form. Did it work like this before? Are you supposed to be able to change the titles of referenced entities in the Tagify widget? If so, this should be fixed.

    It seems there might be a misunderstanding about how tag editing works. When you edit a tag, it doesn't automatically update the referenced content associated with that tag. Instead, the tag itself is modified. For example, if you change a tag from 'Orange' to Apple, it simply updates the tag label. If 'Apple' already exists, it switches to that tag; otherwise, it creates a new tag (if auto-creation is enabled). This functionality has always worked in this way.

  • 🇧🇪Belgium DieterHolvoet Brussels

    Okay, good to know! Thanks for the explanation.

  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇪🇸Spain gxleano Cáceres
  • Status changed to Fixed 3 months ago
  • 🇪🇸Spain gxleano Cáceres

    It will be included on release 1.2.10

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 3 months ago
    2 pass
  • 🇧🇪Belgium DieterHolvoet Brussels

    Thanks for your work! I'll create a separate issue for the alter hook.

  • Status changed to Fixed 3 months ago
  • 🇪🇸Spain gxleano Cáceres
  • 🇪🇸Spain gxleano Cáceres
  • 🇪🇸Spain gxleano Cáceres
  • 🇪🇸Spain gxleano Cáceres
Production build 0.69.0 2024