Seamless entity reference autocomplete integration

Created on 25 July 2016, about 9 years ago
Updated 9 August 2023, about 2 years ago
✨ Feature request
Status

Needs work

Version

2.0

Component

User interface

Created by

πŸ‡¨πŸ‡­Switzerland miro_dietiker Switzerland

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA

    I think we should try to get the updated for 8.x-2.x.

  • πŸ‡΅πŸ‡±Poland gugalamaciek

    This patch adds one more feature - "Advanced search" link at the end of autocomplete suggestions. When clicked, it opens entity browser.

  • πŸ‡΅πŸ‡±Poland gugalamaciek

    I added preview improvement. So now, when something is selected you can setup preview of it in widget configuration. How it looks like:

  • πŸ‡§πŸ‡ͺBelgium rp7

    Re-rolled against latest 2.x + fixed an issue when copy/paste something in the autocomplete field (this issue was introduced in patch in #31).

  • πŸ‡¨πŸ‡¦Canada man-1982

    Reviewed and tested.
    Drupal 10.3
    MR was applied without any issue.
    Suggest adding MR
    thanks

  • πŸ‡΅πŸ‡±Poland gugalamaciek

    Minor improvement: The preview remove button form #name was not always unique.

  • Status changed to Needs review 8 months ago
  • πŸ‡§πŸ‡ͺBelgium rp7

    Patch in #34 gave me JavaScript issues on Drupal 10.4.6. event.target.preventDefault(); was being called where event.target was undefined. Appeared an issue with the order of JavaScript being loaded. Added small adjusment to make sure the JavaScript is loaded after autocomplete is initialized.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    This functionality would still be really fantastic and a great improvement for Drupal!

    Not being forced to decide for the easy and quick autocomplete widget, if you know the label of an entity, but also having the option to alternatively use entity browser alternatively on the same widget, would be absolutely best for more complex use-cases.

    On top it would be a dream to have the option to create a new or edit the referenced entity in a modal, but that's a different topic. Having all that would make things really complete and useful!

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    PS: Let's switch to using a MR instead of patches! Anyone else interested in pushing this over the finish line?

  • First commit to issue fork.
  • @grevil opened merge request.
  • πŸ‡©πŸ‡ͺGermany Grevil

    This should be it! Please review!

  • πŸ‡©πŸ‡ͺGermany Grevil

    Tests fail because of πŸ› Fix arguments for tests Active .

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡©πŸ‡ͺGermany Grevil

    A few things are still not perfect.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Based on a very quick test, some first feedback:

    * Doesn't seem to work at all on cardinality 1 fields, I'd want to use this for the paragraphs_library paragraph type, which is one of those. I get a button
    * should use smaller button classes on Claro/gin, they seem huge.
    * add another item and select button to open entity browser are IMHO pretty confusing and not a great user experience. maybe the the entity browser button could be on top, maybe both small next to each other with some guidance on which does what?
    * edit doesn't seem to use the same dialog system as the regular entity browser widget

    (we have the widget pretty heavily customized in our project, with custom edit/delete icons on top of the previews instead of buttons, so I'm not 100% sure if anything affects that, didn't test on plain claro yet)

  • πŸ‡©πŸ‡ͺGermany Grevil

    @rp7

    Patch in #34 gave me JavaScript issues on Drupal 10.4.6. event.target.preventDefault(); was being called where event.target was undefined.

    That is, because there is no event.target.preventDefault(). There is only event.preventDefault(), see https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault.

    Manually adjusting the weight in the library is not recommended and messes with code execution timings, which leads to frustrating debugging sessions. Please avoid it.

  • πŸ‡©πŸ‡ͺGermany Grevil

    @berdir, thanks for the feedback!

    Doesn't seem to work at all on cardinality 1 fields, I'd want to use this for the paragraphs_library paragraph type, which is one of those. I get a button but no autocomplete field

    This sounds weird! I have only tested it with target entity type being "node". Could you test the latest MR, if that is still the case now?

    should use smaller button classes on Claro/gin, they seem huge.

    Definitely. A Colleague of mine could possibly fix up the styling.

    add another item and select button to open entity browser are IMHO pretty confusing and not a great user experience. maybe the entity browser button could be on top, maybe both small next to each other with some guidance on which does what?

    Ok, I'll take a look on Monday.

    edit doesn't seem to use the same dialog system as the regular entity browser widget

    Hm, could not reproduce this behavior, but maybe I misunderstand. Could you elaborate

    Generally feel free to do some final touches here! This was quite the pain to finalize.

    I think the main problem is, that this Widget extends "EntityReferenceAutocompleteBrowserWidget" instead of "EntityReferenceBrowserWidget", and therefore the implementation differs enormously from the original widget.

    But this might have a reason, and I am really thankful that this MR was already this far in development. Thanks all! πŸŽ‰

    Anyway, I think this can get reviewed now. Final touches should still be added. Unsure if we can provide test coverage....

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks @grevil! Great (and really hard) work. Current status attached as static patch.

  • πŸ‡©πŸ‡ͺGermany Grevil

    @thomas.frobieter, please finalize the styling and button placement based on comment #45.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Testing with plain core + paragraphs_demo, I can confirm that things around cardinality 1 were either fixed or are broken due to customizations in our project, will need to check that. I did run into another issue though, something is off with the ajax replacement selector, resulting the whole element being replaced:

    (to reproduce, install paragraphs_demo, switch the from library paragraph to use this with preview and button, then pick an item from the autocomplete selection)

    Another thing I noticed is that there seems to be a replace button but no setting for that (with cardinality 1). The button also seems broken with an ajax error, but could also be related to the bug mentioned above). Seems pointless to have that, as the regular button is always visible and does the same, the code here might be older than the replace feature and might just not account for that?

    Also, the show delete button setting does nothing on multi-cardinality because core now provides one of those by default I assume.

    And definitely needs some UI improvements as mentioned before. Unsure how it should look, and I tend to forget how ugly the default look of entity browser is too, but this is worse. It looks like all elements (textfield + preview + buttons) are just all stuffed together with display: inline-block, so if you have a very short preview, it's just directly after the textfield, and if it's longer, some buttons are after it, some are on the next line.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Hey @berdir, the paragraphs incompatibility is fixed now! There was also an issue with the triggering elements on ajax callback, not being identified correctly (related to πŸ› Wrong triggering element on the form submit after an ajax callback call Active ) that is fixed as well.

    Another thing I noticed is that there seems to be a replace button but no setting for that (with cardinality 1). The button also seems broken with an ajax error, but could also be related to the bug mentioned above). Seems pointless to have that, as the regular button is always visible and does the same, the code here might be older than the replace feature and might just not account for that?

    There is a bug, where entity_browser still provides the old target id even when we already selected a new entity through the browser. The "normal" Entity Browser Widget fixed that through creating a "replace" button, which basically removes the old entity first and then opens the entity browser to select a new one. But for some reason, there is a setting for this in the other Widget. This widget does not have this setting, the replace button is always shown when the autocomplete field is filled, otherwise the normal entity_browser button is shown.
    Before the last commit both the enity_browser button AND the replace button were shown at the same time. This is now fixed as well.
    (Note, that the behavior "[...] removes the old entity first and then opens the entity browser to select a new one", means that closing the entity browser modal, leads to the autocomplete field not being filled anymore, but this happens in the old widget as well and should be fixed in a follow-up issue on both widgets)

    Also, the show delete button setting does nothing on multi-cardinality because core now provides one of those by default I assume.

    Yes, codewise we only add our own remove button, when the setting is activated AND the cardinality is 1. I guess, we should hide the "remove_button" setting, when the field cardinality is set to > 1.

    And definitely needs some UI improvements as mentioned before

    Yes definitely! Although I am unsure if this should be done in a general follow-up issue, since the UI of the original Widget is not very nice either.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Ok, @berdir feel free to do another review! Everything except the style should be to your liking now.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Static patch for the time being.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Found 2 more bugs. Static patch attached.

  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Grevil

    While testing the Widget, I occasionally ran into πŸ› Media Library modal opens randomly on AJAX requests Active .

    Not unsetting '_actions' and 'weight' in the callback, seems to fixed it without any seeming regression.

  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Not unsetting '_actions' and 'weight' in the callback, seems to fixed it without any seeming regression.

    This was introduced in #31 FYI: https://www.drupal.org/files/issues/2024-10-10/entity_browser-2772279-31... β†’ by @gugalamaciek.

    The first patch didn't contain that part of the code.

  • πŸ‡©πŸ‡ͺGermany Grevil

    A few performance fixes and bug fixes. I haven't tested the "preview_view_mode" setting anymore, it might be broken due to https://git.drupalcode.org/project/entity_browser/-/merge_requests/85/di..., but IMO I would better leave it out completely then running into πŸ› Media Library modal opens randomly on AJAX requests Active again, this widget is already complex enough.

    We could re-add the feature in a follow-up issue. (But it might not be broken at all, so we don't have to do anything).

    Current MR as a static patch is attached.

  • πŸ‡©πŸ‡ͺGermany Grevil
Production build 0.71.5 2024