When using Layout Builder, remove contextual links for blocks outside of the current layout

Created on 24 January 2019, over 5 years ago
Updated 8 March 2024, 4 months ago

Problem/Motivation

From discussion in #2938182-9: Design intuitive affordances for Layout Builder (for illustrating which parts of the page are editable in a given context)

One thing that could be very confusing to site builders is that

  1. Using the Layout Builder, Layouts are populated with blocks
  2. You can configure blocks you add and existing blocks in the layout
  3. You configure the existing blocks in the Layout Builder via contextual links
  4. There will usually be other blocks on the page, but out of the Layout Builder controlled sections
  5. For the blocks outside of the sections: You(if you have permission) also can configure these blocks in the Layout Builder via contextual links
  6. If you have Setting Tray enabled configuring the non-Layout Builder blocks happens in the same place as Layout Builder blocks

I think especially if you are configuring a layout override, say for a node, the user may expect that changes they make to any blocks when using the Layout Builder would be overrides just for that node.

But of course if they configure any block not controlled by Layout Builder, say a search block in a sidebar region, this will be global change and has nothing to do with the Layout override.

So hopefully we can at least say
When a user is configuring a layout in Layout Builder they should not be able to edit blocks not controlled by Layout Builder.

I don't think this would really a burden for users and would remove a lot of confusion.

A simple way to do this would be to remove all block contextual links form blocks not controlled by Layout Builder during layout administration.

I think is important because the whole idea of contextual links is that you can make changes in a given context. So I think it would reasonable for the user to assume they can edit blocks "in the context of the layout"(whether default or override).

Proposed resolution

Remove all contextual links for block outside of the layout when using layout builder

There is existing issue #3002608: Remove contextual links not related to layout administration inside layout builder blocks . This could have been one issue but since that one is RTBC I wanted to make this seperate one.
Although the code will be about the same some may think the other issue is a good idea and this one is not. Hopefully everyone will think both are great ideas 😜

Remaining tasks

do it

User interface changes

No contextual links will be available when using the Layout builder that are outside of the Layout builder admin area.

API changes

none

Data model changes

None

Release notes snippet

📌 Task
Status

Fixed

Version

10.2

Component
Layout builder 

Last updated about 8 hours ago

Created by

🇺🇸United States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • Merge request !5400Remove contextual links outside the layout → (Closed) created by srishtiiee
  • Status changed to Needs review 7 months ago
  • First commit to issue fork.
  • Status changed to RTBC 7 months ago
  • 🇺🇸United States smustgrave

    Rebased to run the test-only feature

    1) Drupal\Tests\layout_builder\FunctionalJavascript\ContextualLinksTest::testContextualLinksOutsideLayout
    Behat\Mink\Exception\ExpectationException: An element matching css "[data-contextual-id*='block:block=global_block:']" appears on this page, but it should not.
    /builds/issue/drupal-3028191/vendor/behat/mink/src/WebAssert.php:794
    /builds/issue/drupal-3028191/vendor/behat/mink/src/WebAssert.php:443
    /builds/issue/drupal-3028191/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php:201
    /builds/issue/drupal-3028191/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php:119
    /builds/issue/drupal-3028191/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    Tests: 2, Assertions: 32, Errors: 1.
    

    Tested this manually on a Standard profile install with layout builder enabled
    Checking the title block I see the contextual links
    Applying the MR and refreshing my browser I can no longer see the contextual links for the title.

    Did verify the contextual links within the layout are still functional.

    Went to a random non layout builder page and verified contextual links are unaffected there too.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.2 & MySQL 5.5
    last update 7 months ago
    Patch Failed to Apply
  • Status changed to Needs work 7 months ago
  • 🇮🇳India srishtiiee

    Test needs to be fixed

  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • 🇮🇳India narendraR Jaipur, India
  • 🇮🇳India yash.rode pune

    Tested this manually, It is working as expected and the test coverage is also thorough.

  • Status changed to RTBC 7 months ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.2 & MySQL 5.5
    last update 7 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.2 & MySQL 5.5
    last update 7 months ago
    Patch Failed to Apply
    • lauriii committed 6959691f on 11.x
      Issue #3028191 by srishtiiee, tedbow, smustgrave, narendraR, yash.rode:...
    • lauriii committed 0e430f2a on 10.2.x
      Issue #3028191 by srishtiiee, tedbow, smustgrave, narendraR, yash.rode:...
  • Status changed to Fixed 7 months ago
  • 🇫🇮Finland lauriii Finland

    Committed 6959691 and pushed to 11.x. Also cherry-picked to 10.2.x. Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 6 months ago
  • 🇩🇪Germany Hydra

    Took me a long road to come here. For everyone wondering where their contextual links went when using layout_builder translations with https://www.drupal.org/project/drupal/issues/2946333 📌 Allow synced Layout override Translations: translating labels and inline blocks Needs work or https://www.drupal.org/project/layout_builder_st , the newly introduced JS in this issue removes them.

    I opened an issue for that in the layout_builder_st issue queue: https://www.drupal.org/project/layout_builder_st/issues/3411037 🐛 Contextual links for translation are removed by core Active
    Not sure if this is the right place either...

    Just wanted to let this comment here for others who are debugging this.

  • 🇺🇸United States joegl

    We have a custom module to create block groups in layout builder. The child blocks in the parent block group have their own contextual links defined by the module, and do not have the `layout_builder_block:` start to the contextual ID. This change made the contextual links for child blocks all get removed, and they can no longer be edited, removed, moved, etc.,

    What is the best way to approach changes to our custom module to support this change? Adding the colon `:` to the end here seems a bit heavy handed. If it wasn't there, we could at least update our module to use the `layout_builder_block_` prefix.

  • 🇺🇸United States joegl

    Our solution for this was to patch the one line and adjust the condition to allow our custom blocks as well:

    if (contextualId && !(contextualId.startsWith('layout_builder_block:') || contextualId.startsWith('OUR_CUSTOM_BLOCKS:'))) {
    

    I'd still like to see something more comprehensive to allow customizations like ours if possible. Again, this change makes a lot of assumptions about the desired user experience.

Production build 0.69.0 2024