diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-03-20 19:18:11 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-03-20 19:18:11 +0000 |
commit | 32076b4d32a3cfdd0476bd3488d5160dd46affac (patch) | |
tree | 2ea12412d23f5c077cf20f35a026b683504f3378 /includes | |
parent | c49a925eb8172805389f9d5f341e4acd9f5cd2d4 (diff) | |
download | brdo-32076b4d32a3cfdd0476bd3488d5160dd46affac.tar.gz brdo-32076b4d32a3cfdd0476bd3488d5160dd46affac.tar.bz2 |
- Patch #273137 by pwolanin, David_Rothstein, chx, et al: split navigation to user and administration menu. Will require follow-up patches.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/menu.inc | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/includes/menu.inc b/includes/menu.inc index 706347278..2a8d9959f 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -776,7 +776,7 @@ function menu_get_object($type = 'node', $position = 1, $path = NULL) { * @return * The rendered HTML of that menu on the current page. */ -function menu_tree($menu_name = 'navigation') { +function menu_tree($menu_name) { static $menu_output = array(); if (!isset($menu_output[$menu_name])) { @@ -841,7 +841,7 @@ function menu_tree_output($tree) { * @return * An tree of menu links in an array, in the order they should be rendered. */ -function menu_tree_all_data($menu_name = 'navigation', $item = NULL) { +function menu_tree_all_data($menu_name, $item = NULL) { static $tree = array(); // Use $mlid as a flag for whether the data being loaded is for the whole tree. @@ -937,7 +937,7 @@ function menu_tree_all_data($menu_name = 'navigation', $item = NULL) { * submenu below the link if there is one, and it is a subtree that has the * same structure described for the top-level array. */ -function menu_tree_page_data($menu_name = 'navigation') { +function menu_tree_page_data($menu_name) { static $tree = array(); // Load the menu item corresponding to the current page. @@ -1332,7 +1332,7 @@ function menu_get_names($reset = FALSE) { * Return an array containing the names of system-defined (default) menus. */ function menu_list_system_menus() { - return array('navigation', 'main-menu', 'secondary-menu'); + return array('navigation' => 'Navigation', 'management' => 'Management', 'user-menu' => 'User menu', 'main-menu' => 'Main menu', 'secondary-menu' => 'Secondary menu'); } /** @@ -1349,11 +1349,11 @@ function menu_secondary_menu() { // If the secondary menu source is set as the primary menu, we display the // second level of the primary menu. - if (variable_get('menu_secondary_links_source', 'secondary-menu') == variable_get('menu_main_links_source', 'main-menu')) { + if (variable_get('menu_secondary_links_source', 'user-menu') == variable_get('menu_main_links_source', 'main-menu')) { return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'), 1); } else { - return menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-menu'), 0); + return menu_navigation_links(variable_get('menu_secondary_links_source', 'user-menu'), 0); } } @@ -1583,14 +1583,14 @@ function theme_menu_local_tasks() { /** * Set (or get) the active menu for the current page - determines the active trail. */ -function menu_set_active_menu_name($menu_name = NULL) { +function menu_set_active_menu_names($menu_names = NULL) { static $active; - if (isset($menu_name)) { - $active = $menu_name; + if (isset($menu_names) && is_array($menu_names)) { + $active = $menu_names; } elseif (!isset($active)) { - $active = 'navigation'; + $active = variable_get('menu_default_active_menus', array('management', 'navigation', 'user-menu', 'main-menu')); } return $active; } @@ -1598,8 +1598,8 @@ function menu_set_active_menu_name($menu_name = NULL) { /** * Get the active menu for the current page - determines the active trail. */ -function menu_get_active_menu_name() { - return menu_set_active_menu_name(); +function menu_get_active_menu_names() { + return menu_set_active_menu_names(); } /** @@ -1650,9 +1650,26 @@ function menu_set_active_trail($new_trail = NULL) { $item = $root_item; } } - - $tree = menu_tree_page_data(menu_get_active_menu_name()); - list($key, $curr) = each($tree); + $menu_names = menu_get_active_menu_names(); + $curr = FALSE; + // Determine if the current page is a link in any of the active menus. + if ($menu_names) { + $query = db_select('menu_links', 'ml'); + $query->fields('ml', array('menu_name')); + $query->condition('ml.link_path', $item['href']); + $query->condition('ml.menu_name', $menu_names, 'IN'); + $result = $query->execute(); + $found = array(); + foreach ($result as $menu) { + $found[] = $menu->menu_name; + } + // The $menu_names array is ordered, so take the first one that matches. + $name = current(array_intersect($menu_names, $found)); + if ($name !== FALSE) { + $tree = menu_tree_page_data($name); + list($key, $curr) = each($tree); + } + } while ($curr) { // Terminate the loop when we find the current path in the active trail. @@ -1863,7 +1880,6 @@ function _menu_navigation_links_rebuild($menu) { $menu_links = array(); foreach ($menu as $path => $item) { if ($item['_visible']) { - $item = _menu_link_build($item); $menu_links[$path] = $item; $sort[$path] = $item['_number_parts']; } @@ -1882,7 +1898,7 @@ function _menu_navigation_links_rebuild($menu) { 'has_children', 'updated', )) - ->condition('link_path', $item['link_path']) + ->condition('link_path', $item['path']) ->condition('module', 'system') ->execute()->fetchAssoc(); if ($existing_item) { @@ -1892,17 +1908,22 @@ function _menu_navigation_links_rebuild($menu) { $item['menu_name'] = $existing_item['menu_name']; $item['plid'] = $existing_item['plid']; } + else { + // If it moved, put it at the top level in the new menu. + $item['plid'] = 0; + } $item['has_children'] = $existing_item['has_children']; $item['updated'] = $existing_item['updated']; } if (!$existing_item || !$existing_item['customized']) { + $item = _menu_link_build($item); menu_link_save($item); } } } $paths = array_keys($menu); // Updated and customized items whose router paths are gone need new ones. - $result = db_select('menu_links') + $result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC)) ->fields('menu_links', array( 'link_path', 'mlid', @@ -1927,7 +1948,7 @@ function _menu_navigation_links_rebuild($menu) { db_update('menu_links') ->fields(array( 'router_path' => $router_path, - 'updated' => $updated, + 'updated' => (int) $updated, )) ->condition('mlid', $item['mlid']) ->execute(); |