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

Issue fork drupal-3028191

Command icon 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

tedbow created an issue. See original summary.

tedbow’s picture

Status: Active » Needs review
StatusFileSize
new3.32 KB
new18.59 KB

Ok this patch starts from #3002608-19: Remove contextual links not related to layout administration inside layout builder blocks because that has almost all the code necessary.

So it also will remove all non-layout Builder contextual for block inside the Layout Builder. So if you place View block it doesn't have the "Edit View" block. See that issue for why if is not apparent.

So for not assuming that issue would get in first. Maybe we should just fold it in.

Status: Needs review » Needs work

The last submitted patch, 2: 3028191-2_plus_3002608-19.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xjm’s picture

Title: When using Layout Builder remove contextual links for blocks outside of current layout » When using Layout Builder, remove contextual links for blocks outside of the current layout
xjm’s picture

Issue tags: +Usability
andypost’s picture

I think both issues needs common ability to control contextual additions to render element
Like

$build = [
  '#type' => whatever,
  '#contextual' = [
    ’filter' = [layout_builder, views],
  ],
];
tim.plunkett’s picture

Issue tags: +Blocks-Layouts

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bkosborne’s picture

Here's a quick fix you can place in a custom module to remove all contextual links that are not used by Layout Builder:

/**
 * Implements hook_contextual_links_plugins_alter().
 */
function HOOK_contextual_links_plugins_alter(array &$contextual_links) {
  // Remove all contextual link plugins except for the ones provided by layout
  // builder. The only reason we have contextual links module enabled is because
  // layout builder requires it for editing blocks. Having the contextual links
  // enabled for other things confuses site builders that assume the pencil icon
  // is used for editing layouts.
  foreach ($contextual_links as $key => $contextual_link) {
    if (strpos($key, 'layout_builder') === FALSE) {
      unset($contextual_links[$key]);
    }
  }
}

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

srishtiiee made their first commit to this issue’s fork.

srishtiiee’s picture

Status: Needs work » Needs review

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

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.

srishtiiee’s picture

Status: Reviewed & tested by the community » Needs work

Test needs to be fixed

narendraR made their first commit to this issue’s fork.

narendrar’s picture

Status: Needs work » Needs review
yash.rode’s picture

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

yash.rode’s picture

Status: Needs review » Reviewed & tested by the community

  • 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:...

lauriii’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

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

Status: Fixed » Closed (fixed)

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

hydra’s picture

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 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
Not sure if this is the right place either...

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

joegl’s picture

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 removed the contextual links for the child blocks, and they can no longer be edited, removed, moved, etc.,

What is the best way to approach changes to the 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.

I'm tempted to patch this change out for now on our sites as it makes a lot of assumptions.

joegl’s picture

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 and the approach here is very heavy-handed.