Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Pardon if I've got something wrong here (** newbie **)...
It appears if you set the access control for a menu, then the admin user can't see that menu item.
One work around is to modify the patch supplied with the module for menu.inc as follows:
// If the administrator has changed the item, reflect the change.
if ($item->type & MENU_MODIFIED_BY_ADMIN) {
// patch supplied with menu-by-role module
if (module_exists('menu_per_role') &&
// additional condition to exclude admin from filter I am suggesting:
!user_access('administer nodes') &&
!is_null($access = menu_per_role_access($item->mid))) {
$_menu['items'][$item->mid]['access'] = isset($_menu['items'][$item->mid]['access']) ? $_menu['items'][$item->mid]['access'] && $access : $access;
}
$_menu['items'][$item->mid]['title'] = $item->title;
$_menu['items'][$item->mid]['description'] = $item->description;
$_menu['items'][$item->mid]['pid'] = $item->pid;
$_menu['items'][$item->mid]['weight'] = $item->weight;
$_menu['items'][$item->mid]['type'] = $item->type;
}
Being very new to Drupal, I suspect their might be a nicer way?
Thanks for a great module - just what I needed!
Comments
Comment #1
kingandy CreditAttribution: kingandy commentedI've encountered this sort of thing with a few modules that do things based on roles (TinyMCE is a good one) ... though user #1 is always deemed to have permission for things, it doesn't generally get assumed to have a role. Usually I guess this is because the roles are being used to switch preferences rather than restrict access, but since this is definitely an access thing I agree that it would be a good idea to keep things visible for the Admin user.
I probably wouldn't use the 'administer nodes' pref as a check though - I can imagine cases where you might want to hide particular menu items from some node administrators.
I'd recommend checking for uid==1 instead ... or adding a 'see all menu items' type preference using hook_perm and then checking off that (since user #1 will always evaluate as true for any permission). That would also add flexibility to give other roles global access. It could tie into the permission dropdown, too, removing any global access roles from the list - saving you checking the box every time you restrict access.
That's for somebody else though, for the basic 'see all menu items' priv you'd do something like this:
Then change your code above to:
... Though it might be better to make the change to the menu_per_role_access function instead, so as to avoid trouble for everyone who's already patched their menu.inc file.
Comment #2
teknocat CreditAttribution: teknocat commentedI didn't realize this issue had already been posted and filed a new issue with a simple patch that fixes the "menu_per_role_access" function in the module.
See: #503278: Super admin can't see menu items not allowing access to "authenticated user"
Comment #3
AlexisWilke CreditAttribution: AlexisWilke commentedI applied the fix from #503278
Let me know whether that is good enough, otherwise reopen the issue.
Thank you.
Alexis
Comment #4
kingandy CreditAttribution: kingandy commentedFWIW, the super-quick fix is to put user #1 into the appropriate role.
Comment #6
mpaler CreditAttribution: mpaler commentedSame problem for D6 version.
Nevermind...I have a custom admin role. ..
Comment #7
mpaler CreditAttribution: mpaler commentedsetting back to closed.