Hide administration menu links that do not have visible child links

Created on 28 February 2017, almost 8 years ago
Updated 31 July 2023, over 1 year ago

Follow-up to #2855786: Menu items that link to an empty administration page are not hidden โ†’

Problem/Motivation

For users with limited permissions (i.e. content editors), enabling the "access administration pages" permission makes a lot of menu items appear that they don't have access to, which show a "You do not have any administrative items." message.

Having all these links that go nowhere is not a very good UX:

Steps to reproduce

  1. Cleanly install Drupal using the standard profile
  2. Log in as user 1
  3. Visit /admin/people/create
  4. Create a new user and grant them the role
  5. Open a private browser window
  6. Log in as the newly created editor
  7. Once authenticated, change the menu to its vertical orientation mode (either by clicking the toggle button on the right side of the toolbar or by shrinking your window width until the menu hits its responsive page break)
  8. Expand the menu item
  9. Observe that the menu item is visible (it should not be) and click it
  10. You will be directed to an empty system admin menu block page with the text

Proposed resolution

Don't show menu items that go to empty administration pages by checking if children are accessible in addition to checking the "access administration pages" permission.

Remaining tasks

Patch
Review
Commit

User interface changes

Menu items to empty administration pages will be hidden.

API changes

N/A

Data model changes

N/A

๐Ÿ› Bug report
Status

Closed: duplicate

Version

11.0 ๐Ÿ”ฅ

Component
Menu systemย  โ†’

Last updated about 5 hours ago

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands stefan.r

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • I was able to reproduce this on the tip of the 9.5.x branch and I updated the issue description with steps to reproduce this bug from a clean installation.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update over 1 year ago
    30,329 pass, 2 fail
  • I spent some time trying to get this working by adding an additional access check to all of the routes which use the SystemController::systemAdminMenuBlockPage controller, but I don't think that's going to be a fruitful approach. It's difficult to check access to menu links from that controller and after digging in, it felt a little hacky.

    Instead, I think it might be more useful and generally useful to add a new flag to menu items to indicate whether it should or shouldn't be shown if doesn't have children. Tentatively, I'm naming this flag transitive with a default value of FALSE. The idea is that menu links like People and Development can be marked "transitive" since their only purpose is to transit users from the root page to a child page. Thus, if they have no visible child links, they can be safely elided.

    I'm trying to do that in MenuLinkTree but I'm running into a hiccup because at some point in the process of building a menu link tree, a particular item may not have any children but will have one added later. So, my current code is removing items that it shouldn't because it doesn't have a way to "know" about the child that doesn't exist yet. I think I just have to spend more time with Xdebug.

    The drawback of the menu link tree based approach is that the system menu block pages would still be accessible, even without any links, if a user visited the right URL directly. That feels like a separate issue that could be handled in a follow-up though. All we'd need to do would be to throw a 403 or 404 HTTP exception in the controller instead of printing out the message.

  • last update over 1 year ago
    30,283 pass, 29 fail
  • @gabesullice opened merge request.
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    30,283 pass, 29 fail
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • Needs work for an update hook to add the transitive column to existing sites.

  • last update over 1 year ago
    30,322 pass, 2 fail
  • Status changed to Needs review over 1 year ago
  • Okay, I added code to update the database schema on existing sites. I was expecting to write an update hook to do this, but it seems like the default menu tree storage service handles its own schema changes, so I made my changes in there instead. This probably needs special attention.

    Needs review for tests.

  • Status changed to Needs work over 1 year ago
  • Needs work to update the toolbar tests, which makes sense.

  • I'm trying to do that in MenuLinkTree, but I'm running into a hiccup because, at some point in the process of building a menu link tree, a particular item may not have any visible children even though one will be added later. Thus, my current code is removing items that it shouldn't because it doesn't "know" about the child that doesn't exist yet. I think I just have to spend more time with Xdebug to figure out where these missing child links are added.

    To follow up on this: the issue was in the toolbar module. It does a quirky thing where it only loads the top level of the admin menu, then it loads the subtree of each of those top level items separately, rather than loading the whole tree at once. This explains why I wasn't seeing any children when I was step-debugging the first load of the admin menu (it was only loading a shallow depth).

    Needs work to update the toolbar tests, which makes sense.

    To clarify: it makes sense because I'm fiddling with the menu and the toolbar tests probably make some assumptions that don't hold any longer.

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar.podey

    omkar.podey โ†’ made their first commit to this issueโ€™s fork.

  • last update over 1 year ago
    Custom Commands Failed
  • @omkarpodey opened merge request.
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,869 pass, 2 fail
  • Assigned to omkar.podey
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tim.plunkett Philadelphia
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    @gabesullice et al, great work on this but...
    I have talked with @tim.plunkett and @lauriii and I (we?) think we should close this issue in favor of #296693-257: Restrict access to empty top level administration pages โ†’ from 2008 which has different approach to solve the same general UX problem. See my linked command but basically I think route access a better way to solve this then menu items.

  • Issue was unassigned.
  • Status changed to Closed: duplicate over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tim.plunkett Philadelphia

    +1

Production build 0.71.5 2024