Index: admin_menu.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/admin_menu/admin_menu.inc,v retrieving revision 1.12 diff -u -p -r1.12 admin_menu.inc --- admin_menu.inc 7 Jun 2008 16:33:58 -0000 1.12 +++ admin_menu.inc 7 Jun 2008 23:24:26 -0000 @@ -10,7 +10,8 @@ function _admin_menu_rebuild_links() { // Add normal and suggested items as links. $menu_links = array(); foreach ($menu as $path => $item) { - if (($item['type'] != MENU_CALLBACK) && ($item['_parts'][0] == 'admin') && (count($item['_parts']) > 1)) { + // Exclude menu callbacks, include items below admin/* and node/add/*. + if ($item['type'] != MENU_CALLBACK && (($item['_parts'][0] == 'admin' && count($item['_parts']) > 1) || (isset($item['_parts'][1]) && $item['_parts'][0] == 'node' && $item['_parts'][1] == 'add'))) { // TODO: handle local tasks with wildcards if (!strpos($path, '%')) { $item = admin_menu_link_build($item); @@ -19,7 +20,7 @@ function _admin_menu_rebuild_links() { } } } - admin_menu_adjust_items($menu_links, $sort); + $deleted = admin_menu_adjust_items($menu_links, $sort); if ($menu_links) { // Make sure no child comes before its parent. array_multisort($sort, SORT_NUMERIC, $menu_links); @@ -33,7 +34,7 @@ function _admin_menu_rebuild_links() { // Allow modules to add more links. If you want to alter links saved by // admin_menu, use hook_menu_link_alter() and look for // $item['module'] == 'admin_menu' - $links = module_invoke_all('admin_menu'); + $links = module_invoke_all('admin_menu', $deleted); foreach ($links as $item) { admin_menu_link_save($item); } @@ -52,9 +53,14 @@ function admin_menu_link_build($item) { 'options' => array(), ); $item['options']['alter'] = TRUE; + // DAM does not output item descriptions to prevent mouseover clashes and + // increase page loading performance. However, the following code shows how + // link attributes can be added (for ajaxified DAM functionality later). + /* if (!empty($item['description'])) { $item['options']['attributes']['title'] = $item['description']; } + */ if (!empty($item['query'])) { $item['options']['query'] = $item['query']; } @@ -77,10 +83,15 @@ function admin_menu_link_save($item) { /** * Implementation of hook_admin_menu(). + * + * @param &$deleted + * Array of links under admin/* that were removed by admin_menu_adjust_items(). + * If one of these links is added back, it should be removed from the array. */ -function admin_menu_admin_menu() { +function admin_menu_admin_menu(&$deleted) { global $base_url; + $links = array(); $icon_path = drupal_get_normal_path(variable_get('site_frontpage', 'node')); // Add 'administer' item to the icon menu. @@ -105,7 +116,15 @@ function admin_menu_admin_menu() { 'parent_path' => $icon_path, ); - // Add links to drupal.org. + // Move 'By module' item into Site configuration. + if (isset($deleted['admin/by-module'])) { + $deleted['admin/by-module']['parent_path'] = 'admin/settings'; + $deleted['admin/by-module']['weight'] = -10; + $links[] = $deleted['admin/by-module']; + unset($deleted['admin/by-module']); + } + + // Add link to drupal.org. $links[] = array( 'title' => 'Drupal.org', 'path' => 'http://drupal.org', @@ -126,27 +145,51 @@ function admin_menu_admin_menu() { } $url = 'http://drupal.org/project/issues/'. $info['project']; $links[] = array( - 'title' => check_plain($info['name']) . 'issue queue', + 'title' => check_plain($info['name']) . ' issue queue', 'path' => $url, 'parent_path' => 'http://drupal.org', ); } + // Add 'Create ' items to Content management menu. - $links[] = array( - 'title' => 'Create content', - 'path' => 'node/add', - 'weight' => -100, - 'parent_path' => 'admin/content', - ); + if (isset($deleted['node/add'])) { + $deleted['node/add']['parent_path'] = 'admin/content'; + $deleted['node/add']['weight'] = 0; + $links[] = $deleted['node/add']; + unset($deleted['node/add']); + } + $content_types = array(); foreach (node_get_types('types', NULL, TRUE) as $type) { $type_url_str = str_replace('_', '-', $type->type); - $path = 'node/add/'. $type_url_str; - $links[] = array( - 'title' => $type->name, - 'path' => $path, - 'weight' => -100, - 'parent_path' => 'node/add', - ); + $type_add_path = 'node/add/' . $type_url_str; + if (isset($deleted[$type_add_path])) { + $links[] = $deleted[$type_add_path]; + unset($deleted[$type_add_path]); + } + $type_edit_path = 'admin/content/node-type/' . $type_url_str . '/edit'; + if (isset($deleted[$type_edit_path])) { + $deleted[$type_edit_path]['title'] = 'Edit @content-type'; + $deleted[$type_edit_path]['title arguments'] = array('@content-type' => $type->name); + $deleted[$type_edit_path]['parent_path'] = 'admin/content/types'; + $links[] = $deleted[$type_edit_path]; + unset($deleted[$type_edit_path]); + $content_types[$type_url_str] = $type_edit_path; + } + } + // CCK support. + if (module_exists('content')) { + foreach ($deleted as $path => $item) { + if (isset($item['_parts'][3]) && isset($content_types[$item['_parts'][3]])) { + if (!isset($item['_parts'][5]) || $item['_parts'][4] != 'display') { + $deleted[$path]['parent_path'] = $content_types[$item['_parts'][3]]; + } + else { + $deleted[$path]['parent_path'] = $content_types[$item['_parts'][3]] . '/display'; + } + $links[] = $deleted[$path]; + unset($deleted[$path]); + } + } } // Add devel module links @@ -195,21 +238,29 @@ function admin_menu_admin_menu() { * @param array $sort * An array containing the # parts of each link - must be updated if a link * is added. + * @return + * An array of links that were removed from $menu_links. */ function admin_menu_adjust_items(&$menu_links, &$sort) { global $user, $base_url; $links = array(); + $deleted = array(); - // Change or remove items, or add new top-level items - $add_links['admin/by-module'] = $menu_links['admin/by-module']; + // Change or remove items, or add new top-level items. + $deleted['admin/by-module'] = $menu_links['admin/by-module']; unset($menu_links['admin/by-module'], $sort['admin/by-module']); + $deleted['admin/by-task'] = $menu_links['admin/by-task']; unset($menu_links['admin/by-task'], $sort['admin/by-task']); - // Remove "edit" links - foreach (node_get_types('types', NULL, TRUE) as $type) { - $type_url_str = str_replace('_', '-', $type->type); - $path = 'admin/content/node-type/'. $type_url_str .'/edit'; - unset($menu_links[$path], $sort[$path]); + // Remove certain links to re-position them in admin_menu_admin_menu(). + foreach ($menu_links as $path => $link) { + // Remove links below + // - admin/content/node-type/* + // - node/add* + if (strpos($path, 'admin/content/node-type/') !== FALSE || strpos($path, 'node/add') !== FALSE) { + $deleted[$path] = $link; + unset($menu_links[$path], $sort[$path]); + } } // Add the icon containing special links. @@ -229,7 +280,8 @@ function admin_menu_adjust_items(&$menu_ 'options' => array('extra class' => 'admin-menu-action admin-menu-icon admin-menu-users', 'html' => TRUE), ); $links[] = array( - 'title' => 'Log out', + 'title' => 'Log out @user', + 'title arguments' => array('@user' => $user->name), 'path' => 'logout', 'weight' => -100, 'options' => array('extra class' => 'admin-menu-action admin-menu-logout'), @@ -241,6 +293,6 @@ function admin_menu_adjust_items(&$menu_ $sort[$path] = 1; } - return; + return $deleted; }