Community Documentation

Menu system overview

Last updated July 1, 2010. Created by siruguri on January 13, 2007.
Edited by xenophyle, KingMoore, TBarregren, Robert Castelo. Log in to edit this page.

In hook_menu(), you define a menu array, which is an associative array. The keys are Drupal paths (with a twist; see the wildcard page for more), the values are menu entries. One menu entry is again an associative array. A typical entry is:

<?php
  $items
['node/%node'] = array(
   
'title' => 'View',
   
'page callback' => 'node_page_view',
   
'page arguments' => array(1),
   
'access callback' => 'node_access',
   
'access arguments' => array('view', 1),
   
'type' => MENU_CALLBACK,
  );
?>

The menu builder collects these, applies inheritance rules and saves each entry in its row in the menu tables.

When you open a page, the system will generate the ancestors of the given path and ask the database for the menu entry of the ancestor that best fits this path. Then it calls the access callback to determine access. If it's given, it then hands over execution to the page callback.

The system determines that it has not found a path if no item can be retrieved from the database or if the node can not be loaded. (See dynamic argument replacements.) Access denied is solely determined by the access callback/arguments.

The page callback function must return a non-NULL value, if any output is to be displayed in the browser for a given URL. If the function returns no value or a NULL value, Drupal will only render the content created by drupal_page_footer (which in turn is the content created by the hook_exit implementation of all the modules.)

Comments

An overview of what?

All very detailed and accurate information I'm sure, but it's not exactly the overview I was expecting, e.g. how about an explanation of the difference between primary and secondary menus? Perhaps I'm in the wrong place?

Develop for Drupal

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here