Problem/Motivation

Alter contextual links based on roles per block type available in layout builder page.

Steps to reproduce

- Add a Block using the layout builder page
- Login as a contributor role (this role can access and edit the blocks on Layout page)
- The contributor should not be able to "Configure" a custom block of type "MyCustomBlock"
- The administrator (or any other role as desired) is/are the only role(s) that can see and click the "Configure" contextual link for a block of type "MyCustomBlock"

Proposed resolution

Have an additional information available in the $route_parameters for hook_contextual_links_alter(). Add bundle information to layout builder to identify the block type rendered

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

gauravjeet created an issue. See original summary.

gauravjeet’s picture

Title: Add bundle to LayoutBuilder » Add bundle information to LayoutBuilder
gauravjeet’s picture

This bundle information is going to be used in hook_contextual_links_alter() as :

if ($group == 'layout_builder_block') {
    if (isset($links['layout_builder_block_update'])) {
      if ($route_parameters['block_bundle'] == 'my_custom_block') {
        // Load the current user and unset the contextual link
        unset($links['layout_builder_block_update']);
      }
    }
  }
gauravjeet’s picture

Created a patch for this.

gauravjeet’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: layout_builder_add_block_bundle-3305126-4.patch, failed testing. View results

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.

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.

danielveza’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hello! Thanks for raising an issue. I believe this should be working already with the permissions that are already used within Drupal

Can we please get some more detailed steps to replicate in the issue summary starting with a fresh install of D11?

danielveza’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

This has been inactive for 3 months since the last comment that asked for more replication steps. I'm marking this as closed. Thanks!