Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The contextual links appear when rendered entity field widget display is used. So if an unaware user clicks "Edit", actually leaving the editing page and loosing data.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#9 | contextual_links_data.png | 81.26 KB | oknate |
#5 | 3081971-3-5-interdiff.txt | 1.97 KB | arpad.rozsa |
#5 | 3081971-5-disable-contextual.patch | 3.96 KB | arpad.rozsa |
#3 | 3081971-2-3-interdiff.txt | 3.01 KB | arpad.rozsa |
#3 | 3081971-3-disable-contextual.patch | 3.8 KB | arpad.rozsa |
Comments
Comment #2
Primsi CreditAttribution: Primsi at MD Systems GmbH for MD Systems GmbH commentedInitial patch, not test yet. I think we don't have anything that could be just extended easily.
Comment #3
arpad.rozsa CreditAttribution: arpad.rozsa at MD Systems GmbH commentedEntity browser works with entities other than media so this check is not needed.
For the test I found the EntityReferenceWidgetTest would work, so I added the assert there to check if the contextual links don't exist on the page.
Comment #4
BerdirWhat about render-caching?
If the same view mode is used in a different context than entity browser then it would also not show contextual links there.
You can fix that by adding an extra 'entity_browser' key to $build['#cache']['keys']
you don't need to repeat modules from the parent, just add which module you need additionally.
Comment #5
arpad.rozsa CreditAttribution: arpad.rozsa at MD Systems GmbH commentedAdded the cache key and removed the modules list from the test that you suggested.
Comment #6
BerdirI guess it could be argued that having those links there is useful in some cases, but unless your users are experienced and know that they need to open these links in a new tab it could easily lead to data loss.. similar to links in node previews and so on.
Setting to RTBC to get the attention of @oknate and whoever else has an opinion on it, if not sure we could maybe add a setting for it?
Comment #7
oknateI think if someone wants them, they can use widget alter. I think this is good to go.
Comment #8
oknateActually, we may want to use
$build['#contextual_links']['#access'] = FALSE
, instead ofunset($build['#contextual_links']);
It would be easier to override in other modules in hook_entity_view_alter().
Comment #9
oknateAh, I see, it's not a build array at this point.
Comment #12
oknateCommitted, thanks!
🎉