Drupal Menu System
Introduction
Three responsibilities:
- Callback mapping
- access control
- menu customization
Essential code for the menu system is in includes/menu.inc, while optional code that enables such features as customizing menus is in modules/menu.
Callback Mapping
When a web browser makes a request to Drupal it gives Drupal a URL. For example http://example.com/?q=node/3. Drupal trims off the base part and uses the path, for example node/3.
Mapping URLs to Functions
Drupal goes through the following steps when a request comes in:
- Establish the Drupal path.
- Drupal keeps track of which paths map to which callbacks in the menu_router database table and keeps track of menu items that are links in the menu_links table.
- Figure out which entry in the menu_router table corresponds with the Drupal path and build a router item describing the callback to be called.
- Load any objects necessary to pass to the callback.
- Check whether the user is permitted to access the callback.
- Localize the menu item’s title and description for the current language.
- Load any necessary include files.
- Call the callback and return the result, which index.php then passes through theme_page(), resulting in a finished web page.
Creating a Menu Item
The place to hook into the process is through the use of the menu hook in your module.