Download & Extend

Menu items still appear when path access is restricted

Project:Path Access
Version:6.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)

Issue Summary

I've noticed this question asked around the forum, but it doesn't seem like anyone has submitted an issue for the module.

First, I've created a node, with a path alias, and added a menu item in primary links.

Next I set the path access module to restrict anonymous users from viewing that path, and it works, except that the menu item still appears. Doesn't seem like this is optimal.

It seems as if some funcitonality could be borrowed from the Remove Non-viewable Menu Items module.

Comments

#1

Version:5.x-1.1» 5.x-1.x-dev

For future reference the magic is done in:

/**
* Implementation of hook_menu().
* @param may_cache Return cacheable menu items?
* @return array of menu items
*/

function remove_nonviewable_menu_items_menu($may_cache) {
  $poisoned_items = array();

  if ($may_cache) {
    if (module_exists('menu')) {
      $result = db_query(db_rewrite_sql('SELECT m.mid, m.* FROM {menu} m ORDER BY m.mid ASC', 'm', 'mid'));
      while ($item = db_fetch_object($result)) {
        $normal_path = drupal_get_normal_path($item->path);
        if (substr($normal_path, 0, 5) == 'node/') {
          if(is_numeric(substr($normal_path, 5))) {
            $nid = substr($normal_path, 5);
            $node = node_load($nid);
            if (!node_access("view", $node)) {
              // User cannot view this node.  
              $poisoned_items[] = array('path' => $item->path,
                'access' => FALSE,
                'title' => $item->title);
            }
          }
        }
      }
    }
  }
  return $poisoned_items;
}

#2

Status:active» needs review

I tried figuring out how to convert this d5 code to d6 and it didn't work out. There may be still a solution. What I decided to do is use javascript to check all menu items on the loaded page.

Attached is the patch that handles this.

AttachmentSize
hide_menu_js.patch 5.68 KB

#3

Version:5.x-1.x-dev» 6.x-1.x-dev

Could this be handled by http://api.drupal.org/api/function/hook_menu_alter/6 in D6?

#4

Yeah I have the same issue!

#5

I think this should be an option and not set in the code as I like the fact that the menus still show up so the user can see what options they would have as an authenticated user. I would like an option for the path restriction to display the user a popup window with a definable message letting the user know that there is restricted access.

#6

+1 for making this optional

#7

Side note, Nonviewable Menu Items http://drupal.org/project/remove_nonviewable_menu_items is for D5, there is no D6 version.

#8

Another +1 for optional. I definitely want people to see the menu items they don't have access to... so they know what's there :)

#9

Subscribe

#10

+1 for optional. One of the main reasons I'm looking at this module over other access modules is that this one allows the menu items to remain in the menu, meaning that users can still see what menu items would be available if they were logged in.

#11

Status:needs review» needs work

In the Drupal 7 branch, access checking is done using hook_menu_alter and so the menu items are hidden when access to them is restricted - this is Drupal core behavior.

There is a module called always_visible which lets you mark menu items as being always visible regardless of the user's permission to view the content.

It's think it's better to have the access module remove the menu items (as in the case with path_access for D7) as this is standard and expected behavior, and then if people want those menu items to show regardless, then use the always_visible module.

I'm now maintainer of this module, and have been working mainly on the Drupal 7 branch. However, I think it would be good if both the D6 and D7 branches did the same thing - ie. restricting access to a menu item should remove it from the menu, and then use always_visible if you still want it to show. It's a more flexible approach, and is more inline with how other access modules behave.

I don't use the D6 version of this module, but how do you all fee about altering it so that it is more inline with how things are being done in D7? It would probably make upgrading easier for you.

#12

Status:needs work» postponed (maintainer needs more info)

#13

Hi,

Any news on this being 'fixed'. It would be really useful if version 6 worked as per 7.

Cheers
Zap

#14

This is actually documented on the front page... The path access is not checked the same way as the menu otherwise expects.

This being said, I would think that the project page of this module should mention the Menu per Role module as an extension one can use to hide "unwanted" menu items.

Thus, at this point, there is probably no need to make the Path Access 6.x module more complicated than it needs to be. There is no Menu per Role for 7.x (yet) so that could be something to add...

Thank you.
Alexis Wilke

#15

I've added the Menu Per Role module link to the Drupal 6 section of the homepage.

#16

I don't know, always_visible isn't even released yet, and it would be just for 7. I think making it optional for 6 would be ideal - consistency only makes sense if everything else is equal, and in this case it isn't...

nobody click here