'Admin links', 'description' => t('Settings for administration links in node lists.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('admin_links_settings_form'), 'access arguments' => array('administer site configuration'), 'file' => 'admin_links.admin.inc', 'type' => MENU_LOCAL_TASK, ); return $items; } /** * Implements hook_node_view(). */ function admin_links_node_view($node, $view_mode) { $destination = drupal_get_destination(); if (!admin_links_is_node_page($node->nid) && variable_get('admin_links_link_tasks', 1)) { // Move the node local tasks to links when getting links not on the current node page. $local_tasks = admin_links_get_local_tasks('node/' . $node->nid, array('node', $node->nid)); foreach ($local_tasks as $local_task) { // Sanitize the path to a string that can be used as a class. $link_key = 'admin_links_' . preg_replace('/\W+/m', '_', $local_task['path']); $node->content['links']['node']['#links'][$link_key] = array( 'title' => $local_task['title'], 'href' => $local_task['href'], 'query' => $destination, ); $node->content['links']['node']['#links'][$link_key] += $local_task['localized_options']; } } //------ add New content link ------- if (variable_get('admin_links_link_new', 0) && node_access('create', $node)) { $node->content['links']['node']['#links']['admin_links_new'] = array( 'title' => t('New @type', array('@type' => drupal_strtolower(node_type_get_name($node)))), 'href' => 'node/add/' . str_replace('_', '-', $node->type), 'query' => $destination, ); } return $node->content['links']['node']['#links']; } /** * Implements hook_node_view_alter(). */ function admin_links_node_view_alter(&$build) { $links = $build['links']['node']['#links']; foreach ($links as $index => $link) { // Check if each link has an excluded path. if (isset($link['href']) && admin_links_is_link_excluded($link['href'])) { unset($links[$index]); } } $build['links']['node']['#links'] = $links; } /** * Fetches a list of the immediate local tasks for a specific Drupal path. * * @see menu_local_tasks() */ function admin_links_get_local_tasks($path, $map = array()) { static $local_tasks = array(); static $router_items = array(); $path_item = menu_get_item($path); if (!isset($router_items[$path_item['tab_root']])) { $router_items[$path_item['tab_root']] = array(); $result = db_query("SELECT * FROM {menu_router} WHERE tab_root=:tab_root AND path <> :path ORDER BY weight, title", array(':tab_root' => $path_item['tab_root'], ':path' => $path_item['path'])); // $item must be an array (not object) for _menu_translate() while($item = $result->fetchAssoc()) { $router_items[$path_item['tab_root']][] = $item; } } if ($router_items) { $local_tasks[$path] = array(); foreach ($router_items[$path_item['tab_root']] as $item) { // _menu_translate($item, $map, TRUE); _menu_translate($item, $map, TRUE); if ($item['access']) { // Merge some default options for l() to be used later. $item['localized_options'] += array( //'query' => drupal_get_destination(), 'attributes' => array(), ); $item['localized_options']['attributes'] += array( 'title' => $item['description'] ? $item['description'] : $item['title'], ); $local_tasks[$path][] = $item; } } } return $local_tasks[$path]; } function admin_links_is_link_excluded($path) { static $matches = array(); static $excludes; if (!isset($matches[$path])) { if (!isset($excludes)) { $excludes = variable_get('admin_links_exclude', implode("\n", array('node/*/view', 'node/*/devel/*'))); } $matches[$path] = drupal_match_path($path, $excludes); } return $matches[$path]; } /** * Checks if the current page is a node page. * * @param * An optional node ID to check if the current page is a specific node. * @return * TRUE if this is a node page, or FALSE otherwise. */ function admin_links_is_node_page($nid = FALSE) { static $is_node_page = array(); if (!isset($is_node_page[$nid])) { $is_node_page[$nid] = preg_match('%node/' . ($nid ? $nid : '\d+') . '%', $_GET['q']); } return $is_node_page[$nid]; }