Drupal Menu System

Introduction

Three responsibilities:

  1. Callback mapping
  2. access control
  3. 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:

  1. Establish the Drupal path.
  2. 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.
  3. 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.
  4. Load any objects necessary to pass to the callback.
  5. Check whether the user is permitted to access the callback.
  6. Localize the menu item’s title and description for the current language.
  7. Load any necessary include files.
  8. 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.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.