diff options
Diffstat (limited to 'modules/menu')
-rw-r--r-- | modules/menu/menu.api.php | 56 | ||||
-rw-r--r-- | modules/menu/menu.module | 19 |
2 files changed, 75 insertions, 0 deletions
diff --git a/modules/menu/menu.api.php b/modules/menu/menu.api.php index 1339bf04d..65170333c 100644 --- a/modules/menu/menu.api.php +++ b/modules/menu/menu.api.php @@ -199,6 +199,21 @@ * this alone; the default alphabetical order is usually best. * - "menu_name": Optional. Set this to a custom menu if you don't want your * item to be placed in Navigation. + * - "context": (optional) Defines the type of a tab to control its placement + * depending on the requested context. By default, all tabs are only + * displayed as local tasks when being rendered in a page context. All tabs + * that should be accessible as contextual links in page region containers + * outside of the parent menu item's primary page context should be + * registered using one of the following contexts: + * - MENU_CONTEXT_PAGE: (default) The tab is displayed as local task for the + * page context only. + * - MENU_CONTEXT_INLINE: The tab is displayed as contextual link outside of + * the primary page context only. + * Contexts can be combined. For example, to display a tab both on a page + * and inline, a menu router item may specify: + * @code + * 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, + * @endcode * - "tab_parent": For local task menu items, the path of the task's parent * item; defaults to the same path without the last component (e.g., the * default parent for 'admin/people/create' is 'admin/people'). @@ -497,5 +512,46 @@ function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) { } /** + * Alter contextual links before they are rendered. + * + * This hook is invoked by menu_contextual_links(). The system-determined + * contextual links are passed in by reference. Additional links may be added + * or existing links can be altered. + * + * Each contextual link must at least contain: + * - title: The localized title of the link. + * - href: The system path to link to. + * - localized_options: An array of options to pass to url(). + * + * @param $links + * An associative array containing contextual links for the given $root_path, + * as described above. The array keys are used to build CSS class names for + * contextual links and must therefore be unique for each set of contextual + * links. + * @param $router_item + * The menu router item belonging to the $root_path being requested. + * @param $root_path + * The (parent) path that has been requested to build contextual links for. + * This is a normalized path, which means that an originally passed path of + * 'node/123' became 'node/%'. + * + * @see menu_contextual_links() + */ +function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) { + // Add a link to all contextual links for nodes. + if ($root_path == 'node/%') { + $links['foo'] = array( + 'title' => t('Do fu'), + 'href' => 'foo/do', + 'localized_options' => array( + 'query' => array( + 'foo' => 'bar', + ), + ), + ); + } +} + +/** * @} End of "addtogroup hooks". */ diff --git a/modules/menu/menu.module b/modules/menu/menu.module index 1e71297a5..824954d61 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -98,6 +98,7 @@ function menu_menu() { 'title' => 'List links', 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, ); $items['admin/structure/menu/manage/%menu/add'] = array( 'title' => 'Add link', @@ -113,6 +114,7 @@ function menu_menu() { 'page arguments' => array('menu_edit_menu', 'edit', 4), 'access arguments' => array('administer menu'), 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, 'file' => 'menu.admin.inc', ); $items['admin/structure/menu/manage/%menu/delete'] = array( @@ -423,10 +425,27 @@ function menu_block_view($delta = '') { $menus = menu_get_menus(FALSE); $data['subject'] = check_plain($menus[$delta]); $data['content'] = menu_tree($delta); + // Add contextual links for this block. + if (!empty($data['content'])) { + $data['content']['#contextual_links']['menu'] = menu_contextual_links('admin/structure/menu/manage', array($delta)); + } return $data; } /** + * Implement hook_block_view_alter(). + */ +function menu_block_view_alter(&$data, $block) { + // Add contextual links for system menu blocks. + if ($block->module == 'system' && !empty($data['content'])) { + $system_menus = menu_list_system_menus(); + if (isset($system_menus[$block->delta])) { + $data['content']['#contextual_links']['menu'] = menu_contextual_links('admin/structure/menu/manage', array($block->delta)); + } + } +} + +/** * Implement hook_node_insert(). */ function menu_node_insert($node) { |