Problem/Motivation

Since #3558459: Menu access and structure, DisplayBuilderUiHooks::menuLinksDiscoveredAlter() points the Display Builder admin menu link to the instances list for a user who can list instances but not manage profiles. The alter runs during the menu link rebuild, which is stored for every user, so the current user there is whoever triggered the rebuild. Its first check also passes a route name to hasPermission(), where no such permission exists.

Steps to reproduce

  1. Give a role only view display builder instance and access administration pages.
  2. Rebuild the menu links as a user with that role, as a router rebuild in their request does:
    \Drupal::service('account_switcher')->switchTo($user);
    \Drupal::service('plugin.manager.menu.link')->rebuild();
  3. As an administrator, the Display Builder link under Structure now incorrectly opens the instances list instead of the profiles list.

Proposed resolution

  1. Drop menuLinksDiscoveredAlter() from DisplayBuilderUiHooks.
  2. Assign the entity.display_builder_profile.collection menu link a custom class DisplayBuilderMenuLink extending MenuLinkDefault.
  3. In DisplayBuilderMenuLink:
    • getRouteName() dynamically selects the route based on the current user's permissions at runtime.
    • getCacheContexts() includes user.permissions.
  4. Provide a Kernel regression test covering route resolution across user roles and verifying menu rebuilds do not leak routes between users.

Remaining tasks

  • Maintainer review

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Fixed Display Builder structure menu link to dynamically resolve its target route per user permissions and cache by user.permissions.

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

mogtofu33 created an issue. See original summary.

keerthi kumar’s picture

I would like to work on this!

keerthi kumar’s picture

Status: Active » Needs review

Opened MR replacing `menuLinksDiscoveredAlter()` with a dedicated `DisplayBuilderMenuLink` plugin that resolves the route dynamically at runtime based on the current user's permissions, adds the `user.permissions` cache context, and includes a Kernel test verifying route resolution across different user roles and rebuild scenarios.

keerthi kumar’s picture

Issue summary: View changes
keerthi kumar’s picture

Issue summary: View changes
mogtofu33’s picture

Status: Needs review » Needs work

Thanks for jumping on this. Please only set Needs review once the pipeline is green; until then it stays Needs work and do not forget to assign to yourself while working.

Also, please don't rewrite the issue summary: it is HTML, and the Markdown version lost the LLM line and the #3558459: Menu access and structure link. I restored it.

keerthi kumar’s picture

Assigned: Unassigned » keerthi kumar

Thanks for the advice @mogtofu33.

All linters (PHPCS, PHPStan, PHP-CS-Fixer) and the new `DisplayBuilderMenuLinkTest` in MR 603 are passing without any issues.

The last failure in PHPUnit is ComponentValidatorTest::testComponents caused by the new sdc_devel release tagged yesterday that raised an error for required props without defaults (#3551361). It's currently failing on 1.0.x too (pipeline #1065584).

In this MR, should I add `default: primary` into `test_defaults.component.yml` to make the pipeline fully green, or leave this MR to focus only on the menu link?

mogtofu33’s picture

Assigned: keerthi kumar » mogtofu33
Status: Needs work » Needs review

Thanks, the sdc devel error is resolved on 1.0.x, will rebase here, so I put in review for me as you've done the work for the issue.

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.