summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-15 08:29:03 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-15 08:29:03 +0000
commit9b3c8c52732bd977622562285a4d3c77b4adfab7 (patch)
tree8b6bf859f8ac30670c2093992f14aaf07c630e2c
parent7df9394c348525135fc257e0e7e92ee5912e9c55 (diff)
downloadbrdo-9b3c8c52732bd977622562285a4d3c77b4adfab7.tar.gz
brdo-9b3c8c52732bd977622562285a4d3c77b4adfab7.tar.bz2
#553944 by sun: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is generated.
-rw-r--r--includes/menu.inc4
-rw-r--r--modules/system/system.api.php32
2 files changed, 36 insertions, 0 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index 0eb6d6618..9eb248c1b 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -427,6 +427,10 @@ function menu_get_item($path = NULL, $router_item = NULL) {
cache_set($cid, $router_item, 'cache_menu');
}
if ($router_item) {
+ // Allow modules to alter the router item before it is translated and
+ // checked for access.
+ drupal_alter('menu_get_item', $router_item, $path, $original_map);
+
$map = _menu_translate($router_item, $original_map);
$router_item['original_map'] = $original_map;
if ($map === FALSE) {
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 8a67cddff..2ae4fd384 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -850,6 +850,38 @@ function hook_page_build(&$page) {
}
/**
+ * Alter a menu router item right after it has been retrieved from the database or cache.
+ *
+ * This hook is invoked by menu_get_item() and allows for run-time alteration of router
+ * information (page_callback, title, and so on) before it is translated and checked for
+ * access. The passed in $router_item is statically cached for the current request, so this
+ * hook is only invoked once for any router item that is retrieved via menu_get_item().
+ *
+ * Usually, modules will only want to inspect the router item and conditionally
+ * perform other actions (such as preparing a state for the current request).
+ * Note that this hook is invoked for any router item that is retrieved by
+ * menu_get_item(), which may or may not be called on the path itself, so implementations
+ * should check the $path parameter if the alteration should fire for the current request
+ * only.
+ *
+ * @param $router_item
+ * The menu router item for $path.
+ * @param $path
+ * The originally passed path, for which $router_item is responsible.
+ * @param $original_map
+ * The path argument map, as contained in $path.
+ *
+ * @see menu_get_item()
+ */
+function hook_menu_get_item_alter(&$router_item, $path, $original_map) {
+ // When retrieving the router item for the current path...
+ if ($path == $_GET['q']) {
+ // ...call a function that prepares something for this request.
+ mymodule_prepare_something();
+ }
+}
+
+/**
* Define menu items and page callbacks.
*
* This hook enables modules to register paths in order to define how URL