diff --git a/menu_block.module b/menu_block.module index 83cf0c9..1a61957 100644 --- a/menu_block.module +++ b/menu_block.module @@ -265,22 +265,28 @@ function menu_tree_build($config) { } } - // Retrieve all the menus containing a link to the current page. - $result = db_query("SELECT menu_name FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $_GET['q'] ? $_GET['q'] : '')); - foreach ($result as $item) { + // Retrieve all the menus of the items in the active trail. + $active_trail = menu_get_active_trail(); + $menu_names = array(); + foreach (array_reverse($active_trail) as $item) { + $_menu_names = db_query('SELECT menu_name FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => $item['href']))->fetchCol(); + $menu_names = array_merge($menu_names, $_menu_names); + } + // Check each menu. + foreach (array_unique($menu_names) as $menu_name) { // Check if the menu is in the list of available menus. - if (isset($menu_order[$item->menu_name])) { + if (isset($menu_order[$menu_name])) { // Mark the menu. - $menu_order[$item->menu_name] = MENU_TREE__CURRENT_PAGE_MENU; + $menu_order[$menu_name] = MENU_TREE__CURRENT_PAGE_MENU; } else { // Check if the menu matches one of the available patterns. foreach (array_keys($patterns) as $pattern) { - if (preg_match($pattern, $item->menu_name)) { + if (preg_match($pattern, $menu_name)) { // Mark the menu. $menu_order[$pattern] = MENU_TREE__CURRENT_PAGE_MENU; // Store the actual menu name. - $patterns[$pattern] = $item->menu_name; + $patterns[$pattern] = $menu_name; } } }