| 7 system.api.php | hook_menu_link_alter(&$item) |
| 6 core.php | hook_menu_link_alter(&$item, $menu) |
Alter the data being saved to the {menu_links} table by menu_link_save().
Parameters
$item: Associative array defining a menu link as passed into menu_link_save().
See also
hook_translated_menu_link_alter()
Related topics
3 functions implement hook_menu_link_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- hook_translated_menu_link_alter in modules/
system/ system.api.php - Alter a menu link after it has been translated and before it is rendered.
- user_menu_link_alter in modules/
user/ user.module - Implements hook_menu_link_alter().
- user_translated_menu_link_alter in modules/
user/ user.module - Implements hook_translated_menu_link_alter().
1 invocation of hook_menu_link_alter()
- menu_link_save in includes/
menu.inc - Saves a menu link.
File
- modules/
system/ system.api.php, line 1295 - Hooks provided by Drupal core and the System module.
Code
function hook_menu_link_alter(&$item) {
// Make all new admin links hidden (a.k.a disabled).
if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
$item['hidden'] = 1;
}
// Flag a link to be altered by hook_translated_menu_link_alter().
if ($item['link_path'] == 'devel/cache/clear') {
$item['options']['alter'] = TRUE;
}
// Flag a link to be altered by hook_translated_menu_link_alter(), but only
// if it is derived from a menu router item; i.e., do not alter a custom
// menu link pointing to the same path that has been created by a user.
if ($item['link_path'] == 'user' && $item['module'] == 'system') {
$item['options']['alter'] = TRUE;
}
}
Comments
URL arguments
PermalinkNote that if you want to set a link path to a URL containing arguments, you cannot do it in $item['link_path']. Instead you have to do it like this:
$item['options']['query']['ARGUMENT_NAME'] = 'ARGUMENT_VALUE';
That is unless anyone else has a better way??
External links to new windows
PermalinkYou can add this option to the hook_menu_link_alter:
function MODULENAME_menu_link_alter(&$item){
if($item['link_path']=="admin/tutorial14333")
{
$item['options']['attributes']['target'] = '_blank';
}
}