Problem/Motivation
With https://www.drupal.org/project/drupal/issues/3028191 a new UX feature has been introduced to reduce contextual-links noise on layout_builder pages. The chosen selector to remove the contextual links 'layout_builder_block:' does also remove the links provided for translation. This makes this module unusable, thats why I tag this issue as a Bug report.
Steps to reproduce
- Vanilla Drupal 10.2
- Install this module, minimum 2 languages and configure content translation
- Create a node with an overriden layout, a translation and try to translate the inline blocks
There should be no contextual translation links anymore.
Proposed resolution
I have no Idea. I guess it's not really possible to fix this 'clean' in this module. I guess the core patch for st translations should change the change and limit the selector to 'layout_builder_' or something like that.
Temporary solution
For now I can share my ugly, temporary solution which I know is not good practice but makes it work for the moment. Just add the following JavaScript to any js file loaded in layout_builder. For instance in your frontend theme.
$(window).off('drupalContextualLinkAdded');
// Remove all contextual links outside the layout.
$(document).on('drupalContextualLinkAdded', (event, data) => {
const element = data.$el;
const contextualId = element.attr('data-contextual-id');
if (contextualId && !contextualId.startsWith('layout_builder_')) {
element.remove();
}
});
This code does what cores tries to do, but with a suitable selector. We prevent core from doing it's job by removing the event from window since it's triggered also for document we can do this. As far as I can tell, no other core function relies on this, but I can't tell which side effect this might have on contrib modules.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | 3411037-contextual-links-removed-from-core-26.patch | 1.97 KB | smulvih2 |
| #14 | 3411037-contextual-links-removed-from-core.patch | 1.54 KB | carolpettirossi |
Issue fork layout_builder_st-3411037
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
Comment #3
hydra commentedI decided to add this as a MR for this module, so people can get a patch for the workaround and don't need to add the code by them self.
Comment #4
tomsaw commentedSame here. Thanks for the workaround @Hydra! Saved my evening.
Comment #5
millerrs commentedSaved me as well. Content editors reported this issue after updating to Drupal 10.2. A big thank you to @Hydra. Also, let's escalate the severity of this issue. Without this patch, users cannot translate layouts, which is a key functionality of this module.
Comment #6
joe_carvajalThis one did the trick for me too, thank you!
Comment #7
millerrs commentedComment #8
kmontyI'd say this is `Needs Work`, as this is an `ugly, temporary solution`.
At the very least, it should remove the dependency on jQuery.
Comment #9
owilliwoPatch is working well on my english/french site !
Thanks a lot.
Here is my "Layout Builder Stack":
Comment #10
junkunczWorks for me as well, thanks!
I agree with @kmonty regarding the refactoring so jQuery should be dropped out (as far as I know vanilla js should be enough there).
End of security support for 10.1.x. is closer than you think so I suggest to remove jQuery then create a follow-up ticket to do a proper fix and merge this MR (of course recheck it first).
Comment #11
fagoI agree, the dependency on jquery should not block moving on here. Setting back to RTBC then.
Comment #12
slideaway commented@hydra Could you clarify what I need to do to install this fix? I've never installed a fix like this and haven't had any luck trying to implement it.
Comment #13
hydra commented@slideaway Oh you need to download the patch from the merge request. Here is some documentation on how to do this: https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr... And of course you need to apply the patch to your version of layout_builder_st.
Comment #14
carolpettirossi commentedDownloading the diff and uploading the patch to your local repo is the recommended approach.
However, I'm attaching the patch from the MR here in case someone is used to this old approach of adding patches to the issue.
The code works successfully in my case. Can't wait to see this merged and released.
Comment #15
slideaway commentedI was able to successfully add the patch and got things working again, thanks for aiming me in the right direction @hydra.
And thank you @carolpettirossi, I didn't actually know that was the old approach versus the new preferred way. I'd just been adding them to my composer.json using composer-patches from support threads like this, so I was unfamiliar with how to do it the way Hydra had mentioned.
Comment #16
nelo_drup commentedIn my case it doesn't work at all, the tranleta option still doesn't appear or maybe I need to configure something else
Comment #17
igorgoncalves commented@carolpettirossi patch fixed the contextual link issue and they're back!
Thanks carol.
But in my project it ending up showing another issue after trying to editing blocks using those links, and this issue/patch helps me:
https://www.drupal.org/project/drupal/issues/3208687
sharing just in case another one faces the same.
Comment #18
heddn+1 on RTBC. LGTM
Comment #19
juagarc4 commentedHi all,
The patch #14 works in my project properly and no other issues were found by testing it.
Context:
Drupal 10.3.5
Layout Builder ST: 1.0-alpha3
PHP 8.3
+1 on RTBC.
Comment #20
joseph.olstadI've included this fix in the Drupal 11 compatibility merge request.
Comment #21
joseph.olstadOk, so now that we have a 2.0.x branch , (working), upgrade to 2.0.x, run drush updb first before a cache rebuild, then rebuild cache, review the MR 5
Comment #22
joseph.olstadRestoring back to RTBC, since this was RTBC previously.
Comment #23
joseph.olstadSomething may have happened after D10.2 because even with this patch installed, I do not see the contextual link for translation. Probably due to an upstream change they probably finished it off.
Comment #24
joseph.olstadThis workaround fix appears to have been broken some time after Drupal 10.2
I no longer see the translation contextual link with or without the patch using any version of layout_builder_st and Drupal 10.4.x / 11.1.x .
Comment #26
smulvih2Adding a patch here for alpha3 that excludes the last commit that adds to .gitlab-ci.yml, since this file doesn't exist in the alpha3 branch. This is needed for WxT 5.4.x.
Comment #27
joseph.olstad@smulvih2 , not sure if this patch even works anymore, although it doesn't appear to cause any harm.
Comment #28
joel_osc commentedFYI I think this just broke 5.3 wxt builds because they use:
I have had to add it to the patches-ignore section of the local composer.json for now to get builds to work.
Comment #29
joseph.olstad@joel_osc , actually I think it's MR6 that is the gotcha , @liam morland combined two patches into one. With that said, I'm going dizzy looking at patches all day long.
Ideally some of these fixes eventually get merged so that we don't have to use so many patches.
Comment #30
liam morlandI haven't worked on merge request 6.
Composer files shouldn't refer to patches like: https://git.drupalcode.org/project/layout_builder_st/-/merge_requests/5....
These change anytime someone makes a commit so you can't be sure you'll get the same code each time you build.
Comment #31
dan612 commentedI think the issue is in claro_preprocess_block().
This patch (which is taken from the patch here) brings them back. They seem to be inconsistent - sometimes have to refresh the page a few times before they show up...but from what I can tell they always come back eventually. Patch is for 10.4.x.
Comment #32
liam morlandThe merge request currently targets 8.x-1.x. It should probably target 2.0.x.
Comment #34
heddnThis resolves some of the issues. Working to clean-up as many errors as possible so the D11 upgrade path doesn't have problems.
Comment #35
joseph.olstad@heddn, why was this merged into 8.x-1.x ?
2.x-dev has had a lot of work gone into it.
Comment #36
joseph.olstadComment #38
heddnMerged into 2.x as well.
Comment #39
joseph.olstadThanks