New hooks for altering menu items

Last modified: October 17, 2008 - 21:29

The Drupal 6.x menu system introduces two new _alter hooks for changing the items being saved to the {menu_router} or {menu_links} tables.

hook_menu_alter() is invoked via drupal_alter() as part of menu_router_build() before the menu items (which define all valid Drupal paths) are saved to the {menu_router} table.

A Drupal path is the string such as 'node' in example.com?q=node, or assuming clean URLs, example.com/node. Each path in {menu_router} is unique. For convenience, a menu link (see below) corresponding to the path is usually added to the navigation menu.

This alter hook might be used, for example, to change the access callback that determines who can view the corresponding page, or to change any other property declared by a module in hook_menu.

hook_menu_link_alter() is invoked via drupal_alter() as a part of menu_link_save() before a link (an item visible in a menu like the Navigation menu) is saved to the {menu_links} table. Links are hierarchical, and there may be many links to the same path. This hook might be used, for example, to add a particular CSS class to some links, or to append a string to the link text.

 
 

Drupal is a registered trademark of Dries Buytaert.