function hook_menu_alter

You are here

7 system.api.php hook_menu_alter(&$items)
6 core.php hook_menu_alter(&$items)

Alter the data being saved to the {menu_router} table after hook_menu is invoked.

This hook is invoked by menu_router_build(). The menu definitions are passed in by reference. Each element of the $items array is one item returned by a module from hook_menu. Additional items may be added, or existing items altered.

Parameters

$items: Associative array of menu router definitions returned from hook_menu().

Related topics

1 function implements hook_menu_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_menu_alter in modules/comment/comment.module
Implements hook_menu_alter().
1 invocation of hook_menu_alter()
menu_router_build in includes/menu.inc
Collects and alters the menu definitions.

File

modules/system/system.api.php, line 1292
Hooks provided by Drupal core and the System module.

Code

function hook_menu_alter(&$items) {
  // Example - disable the page at node/add
  $items['node/add']['access callback'] = FALSE;
}

Comments

The following implements hook_menu_alter to remove access to the "forum" tab for the anonymous user:

/**
* Implements hook_menu_alter.
* Check access for forum menu item.
*/
function MYMODULE_menu_alter(&$items) {
  $items['forum']['access callback'] = '_accesscheck';
}

/**
* Callback to disallow access for the anonymous user.
*/
function _accesscheck(){
  global $user;
  return $user->uid;
}

If you do not grant the anomymous user access to forum content, the anomymous user still has access to the forum landing page. This is rather pointless, so the example above is useful if you want to avoid this.

A lot of projects we do require hiding the standard "/node" page (you can change the front page, but /node stays active)

/**
* Restrict access to /node
*/
function MODULE_menu_alter(&$items) {
    $items['node']['access callback'] = FALSE;
}