Last updated February 19, 2008. Created by drumm on May 30, 2005.
Edited by ax, puregin. Log in to edit this page.
The Drupal menu system got a complete rewrite. The new features include:
- The administrator may now customize the menu to reorder, remove, and add items.
- Menu items may be classified as "local tasks," which will by default be displayed as tabs on the page content.
- The menu API is much more consistent with the rest of Drupal's API.
The menu() function is no more. In its place, we have hook_menu(). The old hook_link() remains, but will no longer be called with the "system" argument. The hook reference in the Doxygen documentation details all the specifics of this new hook. In short, rather than making many calls to menu() in your hook_link() implementation, you will implement hook_menu() to return an array of the menu items you define.
As an example, the old pattern:
<?php
function blog_link($type, $node = 0, $main) {
global $user;
if ($type == 'system') {
menu('node/add/blog', t('blog entry'), user_access('maintain personal blog') ? MENU_FALLTHROUGH : MENU_DENIED, 0);
menu('blog', t('blogs'), user_access('access content') ? 'blog_page' : MENU_DENIED, 0, MENU_HIDE);
menu('blog/'. $user->uid, t('my blog'), MENU_FALLTHROUGH, 1, MENU_SHOW, MENU_LOCKED);
menu('blog/feed', t('RSS feed'), user_access('access content') ? 'blog_feed' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
}
}
?>becomes:
<?php
function blog_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'),
'access' => user_access('maintain personal blog'));
$items[] = array('path' => 'blog', 'title' => t('blogs'),
'callback' => 'blog_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'),
'access' => user_access('maintain personal blog'),
'type' => MENU_DYNAMIC_ITEM);
$items[] = array('path' => 'blog/feed', 'title' => t('RSS feed'),
'callback' => 'blog_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
}
return $items;
}
?>Drupal now distinguishes between 404 (Not Found) pages and 403 (Forbidden) pages. To accommodate this, modules should abandon the practice of not declaring menu items when access is denied to them. Instead, they should set the "access" attribute of their newly-declared menu item to FALSE. This will have the effect of the menu item being hidden, and also preventing the callback from being invoked by typing in the URL. Modules may also want to take advantage of the drupal_access_denied() function, which prints a 403 page (the analogue of drupal_not_found(), which prints a 404).