hook_menu
Definition
hook_menu()
developer/hooks/core.php, line 912
Description
Define menu items and page callbacks.
This hook enables modules to register paths, which determines whose requests are to be handled. Depending on the type of registration requested by each path, a link is placed in the the navigation block and/or an item appears in the menu administration page (q=admin/menu).
This hook is called rarely - for example when modules are enabled.
- "title": Required. The untranslated title of the menu item.
- "description": The untranslated description of the menu item.
- "page callback": The function to call to display a web page when the user visits the path. If omitted, the parent menu item's callback will be used instead.
- "page arguments": An array of arguments to pass to the page callback function. Integer values pass the corresponding URL component (see arg()).
- "access callback": A function returning a boolean value that determines whether the user has access rights to this menu item. Defaults to user_access() unless a value is inherited from a parent menu item..
- "access arguments": An array of arguments to pass to the access callback function. Integer values pass the corresponding URL component.
- "weight": An integer that determines relative position of items in the menu; higher-weighted items sink. Defaults to 0. When in doubt, leave this alone; the default alphabetical order is usually best.
- "type": A bitmask of flags describing properties of the menu item.
Many shortcut bitmasks are provided as constants in menu.inc:
- MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be moved/hidden by the administrator.
- MENU_CALLBACK: Callbacks simply register a path so that the correct function is fired when the URL is accessed.
- MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the administrator may enable.
- MENU_LOCAL_TASK: Local tasks are rendered as tabs by default.
- MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one "default" task, that links to the same path as its parent when clicked.
For comprehensive documentation on the menu system, see http://drupal.org/node/102338 .
Return value
An array of menu items. Each menu item has a key corresponding to the Drupal path being registered. The item is an associative array that may contain the following key-value pairs:
Related topics
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
Code
<?php
function hook_menu() {
$items = array();
$items['blog'] = array(
'title' => 'blogs',
'page callback' => 'blog_page',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
$items['blog/feed'] = array(
'title' => t('RSS feed'),
'page callback' => 'blog_feed',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
?> 