Contextual links for translation are removed by core

Created on 27 December 2023, 11 months ago
Updated 17 September 2024, 2 months ago

Problem/Motivation

With https://www.drupal.org/project/drupal/issues/3028191 πŸ“Œ When using Layout Builder, remove contextual links for blocks outside of the current layout Fixed 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.

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Hydra

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024