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.
To disable a menu with all submenus try to add the next code in a includes/menu.inc in the _menu_build_visible_tree Function at line 1179:
if (module_exists('menu_per_role') && !is_null($access = menu_per_role_access($pid))) {
if( $access == 0 ){
return array();
}
}
like this:
/**
* Find all visible items in the menu tree, for ease in displaying to user.
*
* Since this is only for display, we only need title, path, and children
* for each item.
*/
function _menu_build_visible_tree($pid = 0) {
global $_menu;
if (isset($_menu['items'][$pid])) {
$parent = $_menu['items'][$pid];
$children = array();
if (isset($parent['children'])) {
usort($parent['children'], '_menu_sort');
foreach ($parent['children'] as $mid) {
$children = array_merge($children, _menu_build_visible_tree($mid));
}
}
$visible = ($parent['type'] & MENU_VISIBLE_IN_TREE) ||
($parent['type'] & MENU_VISIBLE_IF_HAS_CHILDREN && count($children) > 0);
$allowed = _menu_item_is_accessible($pid);
<strong>
if (module_exists('menu_per_role') && !is_null($access = menu_per_role_access($pid))) {
if( $access == 0 ){
return array();
}
}
</strong>
if (($parent['type'] & MENU_IS_ROOT) || ($visible && $allowed)) {
$_menu['visible'][$pid] = array('title' => $parent['title'], 'path' => $parent['path'], 'children' => $children, 'type' => $parent['type']);
foreach ($children as $mid) {
$_menu['visible'][$mid]['pid'] = $pid;
}
return array($pid);
}
else {
return $children;
}
}
return array();
}
Please check if it works fine in your system.
Regards.
Comments
Comment #1
rfranquet CreditAttribution: rfranquet commentedWARNING !!!
Please, remove
<strong>
and</strong>
Comment #2
AlexisWilke CreditAttribution: AlexisWilke commentedThis is now 2 years old so I'm closing it. If you can co-maintain, let us know.