| 6 core.php | hook_menu_alter(&$items) |
| 7 system.api.php | hook_menu_alter(&$items) |
| 8 system.api.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
File
- modules/
system/ system.api.php, line 1238 - Hooks provided by Drupal core and the System module.
Code
<?php
function hook_menu_alter(&$items) {
// Example - disable the page at node/add
$items['node/add']['access callback'] = FALSE;
}
?> Login or register to post comments
Comments
When I alter a item,a blank item is be added to the navigation.
I alter a menu item as follow:
<?phpfunction menufun_menu_alter(&$items) {
$items['logout']['page callback'] = 'menufun_user_logout';
$items['logout']['access callback'] = 'user_is_logged_in';
unset($items['logout']['file']);
}
?>
It also add a blank item to the navigation.So what's wrong with my code?
You may be wanting to alter
You may be wanting to alter 'user/logout' rather than just 'logout' in case you are using Drupal 7.
You can remove them by
You can remove them by unsetting the variable.
for example
unset($items['user/%user/edit'])
change menu item title
$items['contact']['access callback'] = FALSE;
works fine, but
$items['contact']['title'] = 'Whatever';
does not work. Why?
use
use $items['contact']['title'] = t('Whatever');
its work fine.
You shouldn't use t() in
You shouldn't use t() in Drupal 7 unless the title callback is changed. Drupal core uses
t()function as a default title callback.