Drupal: How to Add a Tab to the Node’s Display?
Display some information related to the current node and display that on a separate tab on the same level as View and Edit.
Solution
Adding of a tab in Drupal 6
Tab for all nodes without access restrictions:
$items[‘node/%node/new_tab’] = array(
‘title’ => ‘New Tab’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK
)
For nods of specified type (‘my_type’ in this example):
$items[‘node/%my_node_type/new_tab’] = array(
‘title’ => ‘New Tab’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK
)
…
function my_node_type_load($arg) {
$node = node_load($arg);
if($node->type == ‘my_type’)
return $node;
return FALSE;
}
Or you can do this when verification of menu item access rights:
/**
* Implementation of hook_menu().
*/
function my_module_menu() {
$items[‘node/%/new_tab’] = array(
‘title’ => ‘Pay Here’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => ‘custom_loader’,
‘access arguments’ => array(1),
‘type’ => MENU_LOCAL_TASK,
);
return $items;
}
function custom_loader($param) {
$node = node_load($param , $revision = NULL, $reset = NULL);
if($node->type == ‘my_node_type’)
return TRUE;
return FALSE;
}
Adding of a tab in Drupal 5
Here how you can add a tab to ‘my_type’ node. The tab will be shown to those users who can view the node:
if (arg(0) == ‘node’ && is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node->type == ‘my_type’) {
$items[] = array(
’path’ => ‘node/’. arg(1) .‘/images‘,
‘title’ => t(’Images’),
‘callback’ => ’show_tab_page’,
‘callback arguments’ => array($node),
‘access’ => node_access(’view’, $node),
‘type’ => MENU_CALLBACK);
}
}
please tell me about Drupal 7: How to Add a Tab to the Node’s Display?