Admin cannot access menu once another role has been selected.

jfall - November 7, 2007 - 00:36
Project:Menu per Role
Version:5.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

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:

<?php
     
// 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!

#1

kingandy - November 27, 2007 - 15:53

I'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:

<?php
function menu_per_role_perm() {
  return array(
'see all menu items');
}
?>

Then change your code above to:

<?php
     
// 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('see all menu items') &&
            !
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;
      }
?>

... 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.

 
 

Drupal is a registered trademark of Dries Buytaert.