diff --git a/i18n_menu/i18n_menu.module b/i18n_menu/i18n_menu.module index f1b62ff..80f7793 100644 --- a/i18n_menu/i18n_menu.module +++ b/i18n_menu/i18n_menu.module @@ -780,8 +780,12 @@ function i18n_menu_init() { if (!empty($tab_root)) { $path_candidates[$tab_root['path']] = $tab_root['path']; } - // Retrieve a list of menu names, ordered by preference. + // Retrieve a list of menu names, ordered by preference. $menu_names = menu_get_active_menu_names(); + // Use an illegal menu name as the key for the preferred menu link. + $selected_menu = MENU_PREFERRED_LINK; + // Put the selected menu at the front of the list. + array_unshift($menu_names, $selected_menu); $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC)); $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path'); @@ -800,24 +804,31 @@ function i18n_menu_init() { foreach ($query->execute() as $candidate) { $candidate['weight'] = $candidate['link_weight']; $candidates[$candidate['link_path']][$candidate['menu_name']] = $candidate; + // Add any menus not already in the menu name search list. + if (!in_array($candidate['menu_name'], $menu_names)) { + $menu_names[] = $candidate['menu_name']; + } } - // Pick the most specific link, in the most preferred menu. - foreach ($path_candidates as $link_path) { - if (!isset($candidates[$link_path])) { - continue; - } + // Store the most specific link for each menu. Also save the most specific + // link of the most preferred menu in $preferred_link. + foreach ($path_candidates as $link_path) { + if (isset($candidates[$link_path])) { foreach ($menu_names as $menu_name) { - if (!isset($candidates[$link_path][$menu_name])) { - continue; - } - $candidate_item = $candidates[$link_path][$menu_name]; - $map = explode('/', $path); - _menu_translate($candidate_item, $map); - if ($candidate_item['access']) { - $preferred_links[$path] = $candidate_item; + if (empty($preferred_links[$path][$menu_name]) && isset($candidates[$link_path][$menu_name])) { + $candidate_item = $candidates[$link_path][$menu_name]; + $map = explode('/', $path); + _menu_translate($candidate_item, $map); + if ($candidate_item['access']) { + $preferred_links[$path][$menu_name] = $candidate_item; + if (empty($preferred_links[$path][MENU_PREFERRED_LINK])) { + // Store the most specific link. + $preferred_links[$path][MENU_PREFERRED_LINK] = $candidate_item; + } + } } - break 2; } } + } } +