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. In Drupal 7 it used to be that these menu items were hidden.

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

Proposed resolution

Don't show menu items that go to empty administration pages by hiding items marked as having children, but where none of the children are accessible.

Remaining tasks

Commit

User interface changes

Menu items to empty administration pages will be hidden.

API changes

N/A

Data model changes

N/A

Comments

stefan.r created an issue. See original summary.

stefan.r’s picture

Project: Drupal core » Admin Toolbar
Version: 8.4.x-dev » 8.x-1.x-dev
Component: other » Code
Category: Bug report » Feature request
Priority: Normal » Major

Reassigning to Admin Toolbar as this is a feature that used to be in admin_menu

stefan.r’s picture

Status: Active » Needs review
StatusFileSize
new2.59 KB
stefan.r’s picture

To test:

- create a user with permission "access administration pages" only
- confirm that before applying the patch, the "configuration" menu has many subitems that, when clicked, display an empty page
- apply patch
- confirm that after applying the patch, the subitems are removed

pwolanin’s picture

This doesn't seem like a core bug per-se. For these certain listing pages you need to add a check beyond the permissions check?

stefan.r’s picture

For now the workaround in this issue should solve the immediate issue with admin_toolbar, created #2856666: Hide administration menu links that do not have visible child links for the core issue.

rutiolma’s picture

Status: Needs review » Reviewed & tested by the community

Just gave it a try and this patch works, fixing the described issue.

stefan.r’s picture

Issue summary: View changes
alan d.’s picture

eme’s picture

Well, as there is already a core patch + a module for fixing it, it would be nice to keep Admin Toolbar clean. A solution would be to integrage Administration links access as a submodule of Admin Toolbar untill this bug in fixed in the core.

I'll ask the maintainer of Administration link access filter and add it at least to the Admin toolbar description page.

agoradesign’s picture

Hi there,

I'm the maintainer of Administration link access filter and I'd fully support this idea of merging this in as sub module - also see my comment at #2866592-2: Merge into Admin Toolbar ?

Please feel free to contact me or even just grab the code and use it :) I'm also frequently online on IRC, most of the time hanging around in #drupal-commerce channel

best regards,
Andreas

alan d.’s picture

already a core patch

Please don't wait for core lol

catch commented 17 November 2010 at 14:29
Version:	7.x-dev	» 8.x-dev
Priority:	Critical	» Major
Issue tags:	-Release blocker, -D7 API clean-up	
agoradesign’s picture

lol, the only positive thing is that it finally wasn't treated as release blocker for D8 :D

hoemmawelt’s picture

Patch #3 applied on 1.19 and it works without errors. (The module also works.)

stefan.r’s picture

@eme I had discussed with core maintainers (pwolanin) and they suggested fixing this in admin toolbar instead. Don't wait for core, because I don't think it will be fixed there.

hoemmawelt’s picture

After updating to 8.3.4 the core module Workflows appears as empty menu item. Is this related to this issue?

Module is disabled.

joekers’s picture

The patch works fine for me.

joekers’s picture

Actually it turns out that the "content" menu link gets removed.

dunebl’s picture

Here is an updated version, rerolled for last dev...

@joekers: Could you check if the user have the right to add some content? (Don't forget to clear the cache before testing)

joekers’s picture

Yep the user has access, they can see and go to the content page without the patch. I first thought it might be due to it not having any children elements, but the "People" link still shows..

dunebl’s picture

@joekers:

You are right... looking at the code, if the user doesn't have the right to access
one of the submenu item of any menu link, the former will be removed (Access:Neutral)

In your use case, the user have only "Access the Content overview page" but he can't add content or anything else that any submenu of the content menu item can provide...

I don't see any easy way to change this... but I think this patch doesn't solve the problem as it is adding another "bug"!

joekers’s picture

The user has access to add content, it was access to the comments (which is the only link under Content) that allowed the Content link to show. This was better than showing all the other unaccessible links for me so I've settled on giving them this permission for now.

dunebl’s picture

FYI, I am using another patch: https://www.drupal.org/node/2731369#comment-12140124 which adds all the local tasks in the admin menu...
This is why I have other sub items in the content menu...
I think, this can solve your use case without adding the comment permission... (But this will not solve this "bug")

chr.fritsch’s picture

Here is a new patch, with fixed tests

rootwork’s picture

+++ b/admin_toolbar.module
@@ -88,3 +91,43 @@ function toolbar_tools_menu_navigation_links(array $tree) {
+ * Removes menu items with subtrees in which none of the children are accessible.
+ *
+ * This fixes a regression in Drupal 8 core and reverts to the Drupal 7 core
+ * behavior, by hiding the menu items.

While I understand this is the (very good) reason for this, do we actually want to say this in the code?

I think the first line says what it does; we might not need further explanation.

fenstrat’s picture

StatusFileSize
new2.97 KB

Here's a reroll of #24 as it no longer applied because the administer site configuration permission in the test was added in #2887439: Fix test.

Also removed the "This fixes a regression..." comment noted by @rootwork in #25 as I also agree it's probably not needed.

jeroen_drenth’s picture

StatusFileSize
new4.19 KB

Path #26 also doesn't apply anymore. Here's a new one. If it passes the tests, can it be commited before this happens again, please?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: menu_items_that_link_to-2855786-26.patch, failed testing. View results

jeroen_drenth’s picture

StatusFileSize
new4.73 KB

Oops, forgot to update the test.

jeroen_drenth’s picture

Status: Needs work » Needs review
adriancid’s picture

@eme as this will be fixed in the future in core, I think that we should merge the @agoradesign project (admin_links_access_filter) as a submodule of Admin Toolbar, so when the problem will be fixed in core we can just delete the submodule, and we don't need to change nothing inside the Admin Toolbar module. I don't know what do you think. In my opinion this can be a great feature for the v1.21.

eme’s picture

I do agree that it does not belong inside Admin Toolbar. Or maybe a separate module that we can deprecate ?

adriancid’s picture

@eme we can create a submodule of Admin Toolbar to fix this problem and put inside the code of the admin_links_access_filter module. I think that @agoradesign think the same #2866592: Merge into Admin Toolbar ?

eme’s picture

Ok, all right and let's go :)

adriancid’s picture

@eme, ok, I will work on this in the next days, for the moment I will open the issue and close this as duplicate :-)

adriancid’s picture

Status: Needs review » Closed (duplicate)

Well the adventure has just started in #2917704: Add Administration links access filter module as Admin Toolbar submodule

Closing as duplicate.

Once we finish I will add credit in the issue to all the people that help here ;-)

adriancid’s picture

ankit agrawal’s picture

Adding admin_links_access_filter module (sub-module of admin_toolbar) fixed the issue for me. Thanks

amneh.shawish’s picture

Enable this module Admin Toolbar Links Access Filter to hide an empty administration page from the menu.