diff --git a/admin_menu.inc b/admin_menu.inc index b34d2d4..8c2b344 100644 --- a/admin_menu.inc +++ b/admin_menu.inc @@ -370,7 +370,7 @@ function admin_menu_expand_args($arguments) { */ function admin_menu_links_menu($tree) { $links = array(); - foreach ($tree as $data) { + foreach ($tree as $key => $data) { // Skip invisible items. if (!$data['link']['access'] || $data['link']['type'] == MENU_CALLBACK) { continue; @@ -392,14 +392,14 @@ function admin_menu_links_menu($tree) { // Remove description to prevent mouseover tooltip clashes. unset($data['link']['localized_options']['attributes']['title']); - $links[$data['link']['mlid']] = array( + $links[$key] = array( '#title' => $data['link']['title'], '#href' => $data['link']['href'], '#options' => $data['link']['localized_options'], '#weight' => $data['link']['weight'], ); if ($data['below']) { - $links[$data['link']['mlid']] += admin_menu_links_menu($data['below']); + $links[$key] += admin_menu_links_menu($data['below']); } } return $links; diff --git a/admin_menu.info b/admin_menu.info index 42b14fd..f2922f9 100644 --- a/admin_menu.info +++ b/admin_menu.info @@ -3,4 +3,7 @@ description = "Provides a dropdown menu to most administrative tasks and other c package = Administration core = 7.x configure = admin/config/administration/admin_menu +; Requires menu_build_tree() conditions; available after 7.10. +; @see http://drupal.org/node/1025582 +dependencies[] = system (>=7.12) files[] = tests/admin_menu.test diff --git a/admin_menu.module b/admin_menu.module index 6fa85f2..bf75ee8 100644 --- a/admin_menu.module +++ b/admin_menu.module @@ -412,8 +412,6 @@ function admin_menu_output() { $content['menu']['#theme'] = 'admin_menu_links'; // Ensure the menu tree is rendered between the icon and user links. $content['menu']['#weight'] = 0; - // Do not sort the menu tree, since it is sorted already. - $content['menu']['#sorted'] = TRUE; // Add menu additions. $content['icon'] = admin_menu_links_icon(); @@ -438,6 +436,32 @@ function admin_menu_output() { } /** + * Implements hook_admin_menu_output_alter(). + * + * @todo This is an addition, not an alter. Add a build hook stage. + */ +function admin_menu_admin_menu_output_alter(&$content) { + // Add "Add content" link tree on the top level. + $link = db_query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")->fetchAssoc(); + $conditions = array(); + for ($i = 1; $i < MENU_MAX_DEPTH; $i++) { + if (!empty($link["p$i"])) { + $conditions["p$i"] = $link["p$i"]; + } + } + $tree = menu_build_tree($link['menu_name'], array( + 'conditions' => $conditions, + 'min_depth' => $link['depth'], + )); + $links = admin_menu_links_menu($tree); + if (!empty($links)) { + $key = key($links); + $links[$key]['#weight'] = -100; + $content['menu'] += $links; + } +} + +/** * Render a themed list of links. * * @param $variables