Sei sulla pagina 1di 4

Drupal 6 Menu System

Drupal 6 menu system provides vast support to build multiple menus in different ways. Developer needs to create an array in hook_menu and return it in the intended format and the menu item will be added to the menu. The same can also be done from the admin panel in case of creating pages etc. Menus can be created from the admin panel in Administrator -> Site Building-> Menus (admin/build/menu). By default there will be 3 menus in a drupal 6 installation. They are Navigation :- The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users. Primary Links :- Primary links are often used at the theme layer to show the major sections of a site. A typical representation for primary links would be tabs along the top. Secondary Links :- Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links.

New menu can be created by clicking on Add Menu. A menu item can be created from the menu or by using hook_menu in your modules. 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. The hook menu can be given in the below way.

My_mod_menu(){ $item = array(); $items['node/%node'] = array( 'title' => 'View', 'page callback' => 'node_page_view', 'page arguments' => array(1), 'access arguments' => array('view', 1), 'type' => MENU_CALLBACK,

); $item['admin/train']= array( 'title' => 'Training Page Title', 'description' => 'All the training Examples.', 'page callback' => 'my_new_training_page', 'access arguments' => array('Training Page'), 'weight' => 0, ); $item['admin/train/page1']= array( 'title' => 'Training Page1 Title', 'description' => 'All the new training Examples.', 'page callback' => 'my_new_training_page1', 'access arguments' => array('Training Page1'), 'weight' => 0, 'type' => MENU_NORMAL_ITEM, ); $item['admin/train/page1/t1']= array( 'title' => 'Training Tab 1', 'description' => 'All the new training Examples.', 'weight' => 0, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $item['admin/train/page1/t2']= array( 'title' => 'Training Tab 2', 'description' => 'All the new training Examples.', 'page callback' => 'my_new_training_tab2', 'access arguments' => array('Training Tab'), 'weight' => 0, 'type' => MENU_LOCAL_TASK, ); return $item; }

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:

"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.. "file": A file that will be included before the callbacks are accessed; this allows callback functions to be in separate files. The file should be relative to the implementing module's directory unless otherwise specified by the "file path" option. "file path": The path to the folder containing the file specified in "file". This defaults to the path to the module implementing the hook. "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. "menu_name": Optional. Set this to a custom menu if you don't want your item to be placed in Navigation. "type": A bitmask of flags describing properties of the menu item. Many shortcut bitmasks are provided as constants in menu.inc: o MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be moved/hidden by the administrator. o MENU_LOCAL_TASK: Local tasks are rendered as tabs by default. o 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.

If the "type" key is omitted, MENU_NORMAL_ITEM is assumed.


hook_menu_alter :- The menu definitions are passed in by reference. Each element of the $items array is one item returned by a module from hook_menu. Additional items may be added, or existing items altered. function my_module_menu_alter(&$items) { $items['user']['type'] = MENU_CALLBACK; $items['user/register']['type'] = MENU_CALLBACK;

$items['user/password']['type'] = MENU_CALLBACK; } hook_menu_link_alter :- is used to alter the menu link or add CSS class to the link or append string text to the link text. function hook_menu_link_alter(&$item, $menu) { // make all new admin links hidden (disabled). if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) { $item['hidden'] = 1; } } For clearing the catch we use menu_rebuild().

Potrebbero piacerti anche