Thanks for making this module, it's exactly what I needed!

I had an issue where custom roles which were allowed to view menu items did not have the menu item appear correctly. I had some custom roles with various menu options, but only the admin users would see the menu.

I traced this to the use of array_keys in the code, which seems to return a sequence (0,1,2...) every time when returning roles assigned to the user. Thus, as long as the assigned role was low enough, it would appear to work (role ID 1 is authenticated user, so this would always work if a menu item is given to this role as long as the user had one additional role, role ID 2 is a custom role, but would also always work if the user was assigned at least 2 additional roles, etc).

I fixed this by updating the function to use array_values instead, which returns the actual role ID's assigned to the user and not the array number.

Patch attached.

CommentFileSizeAuthor
menu_per_role_array_keys.patch1.26 KBCharlie B
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AlexisWilke’s picture

The array_keys() is based on this Drupal Core code:

    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
    while ($role = db_fetch_object($result)) {
      $user->roles[$role->rid] = $role->name;
    }

I'm not too sure why you are having a problem. We want to compare the $role->rid with the menu per role rid defined in $rids array.

Thank you.
Alexis

izmeez’s picture

subscribing. Encountered a similar problem when updating to version 1.8 (http://drupal.org/node/948158)

AlexisWilke’s picture

I'm thinking that you must have a module that transforms the $user->roles array in a totally incorrect way. There is no way that this would fail with a default Drupal installation, whatever the number of roles you have. If you don't mind trying with a Core Drupal install + Menu per Role and no other module... and see what happens.

Note that if this is indeed the case, the erroneous module would need to be fixed because it will cause similar problems for any module that expects the $rid as keys of the $user->roles array.

AlexisWilke’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hi Charlie B.

I just did an update to fix a problem when creating a new node. I'm suspecting that your problem was in link with that... If you would please take the time to update to 1.x-dev to see whether it works for you?

Again, the roles in the $user object cannot be inverted or there is a bigger bug in your install... The array should be (in pseudo code):

  $user->roles[$role_id] = "$role_name";

Thank you.
Alexis

AlexisWilke’s picture

Assigned: Charlie B » Unassigned

izmeez,

I did another update to the 6.x-1.x-dev version which allows you to hide the menus to administrators. I think that's the problem you had. Maybe Charlie B. had that problem too but he's not very talkative...

I'll see that the current version works right for many and create version 1.9 which will hide menus to any administrator (as defined in the menu per role administration window.)

Thank you.
Alexis Wilke

izmeez’s picture

Alexis,

Thanks for the updates. I wasn't having problems with hiding the menus from admins because I wasn't trying to do that, but I will take a look and test the new dev release and report what I find. Unfortunately my time is quite tight for the next few days.

Izzy

AlexisWilke’s picture

Assigned: Unassigned » AlexisWilke
Status: Postponed (maintainer needs more info) » Fixed

Okay, that should be fixed in version 6.x-1.9.

Feel free to re-open the issue if you still have a problem.

Thank you.
Alexis Wilke

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.