Drupal Menu Specifics
Continuing articles devoted to menu in Drupal: its structure, functions, constants and specifics.
Drupal show tabs if there are 2 or more tabs. One tab won’t be shown.
4 level of depth are supported. For example:
function example_module_menu() {
$items[‘node/%/forum/%node’] = array(
‘title’ => ‘forum’,
‘page callback’ => ‘example_module_forum_form’,
‘page arguments’ => array(1, 3),
‘access callback’ => ‘example_module_forum_access’,
‘access arguments’ => array(1),
‘type’ => MENU_LOCAL_TASK,
‘file’ => ‘example_module.pages.inc’,
‘weight’ => 7
);
return $items;
}
Here, path is ‘node/%/forum/%node’, where
- node – null level (isn’t shown in tabs)
- % – first level (isn’t shown in tabs)
- forum – second level (tabs of the first level)
- %node – third level (tabs of the second level)
Page title : you can’t set or change title of a page for second-level tabs because the tabs follows one of the first-level tabs.
To change page title for the second-level tabs, you should do something like this:
/**
* Title callback.
*/
function example_module_page_title($node) {
if ((arg(3) == ‘node’ || arg(3) == ‘edit’) && is_numeric(arg(4))) {
$topic = node_load(arg(4));
drupal_set_title($topic->title);
} else{
drupal_set_title($node->title .’ ‘ . t(‘forum’));
}
return t(‘forum’);
}
function example_module_menu() {
$items[‘node/%node/forum’] = array(
‘title callback’ => ‘example_module_page_title’,
‘title arguments’ => array(1),
‘page callback’ => ‘example_module_forum_form’,
‘page arguments’ => array(1, 3),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK,
‘weight’ => 7,
);
$items[‘node/%node/forum/list’] = array(
‘title’ => ‘forum List’,
‘type’ => MENU_DEFAULT_LOCAL_TASK,
‘weight’ => -20,
);
$items[‘node/%node/forum/node/add’] = array(
‘title’ => ‘Create Discussion’,
‘page callback’ => ‘drupal_get_form’,
‘page arguments’ => array(‘example_module_node_form_reuse’),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘create’, ‘forum’),
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘type’ => MENU_LOCAL_TASK,
‘weight’ => 10,
);
$items[‘node/%/forum/node/%node’] = array(
‘title’ => ‘View Discussion’,
// the next 2 lines aren’t used:
//’title callback’ => ‘example_module_topic_page_title’,
//’title arguments’ => array(1, 4),
‘page callback’ => ‘node_page_view’,
‘page arguments’ => array(4),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘view’, 4),
‘type’ => MENU_LOCAL_TASK,
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘weight’ => -10,
);
$items[‘node/%/forum/edit/%node’] = array(
‘title’ => ‘Edit Discussion’,
‘page callback’ => ‘node_page_edit’,
‘page arguments’ => array(4),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘update’, 4),
‘weight’ => 1,
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘type’ => MENU_LOCAL_TASK,
);
return $items;
}