Menu items still appear when path access is restricted
peligrorice - May 23, 2008 - 01:21
| Project: | Path Access |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
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.

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