February 11th, 2010 | in
And another Drupal tip for today: "How to add a tab to the node in Drupal":
Put this snippet in hook_menu of your new module:
$items['node/%node/new_tab'] = array(
'title' => 'New Tab',
'page callback' => 'mycallback',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK
)This tab is going to be shown on any node type and without access restrictions,
however, if you need to specify a special node type, 'custom_node' for example, do the following:
put this snippet in hook_menu of your new module:
$items['node/%custom_node/new_tab'] = array(
'title' => 'New Tab',
'page callback' => 'mycallback',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK
)And create a function:
function custom_node_load($arg) {
$node = node_load($arg);
if($node->type == 'custom_node')
return $node;
return FALSE;
}Hope this helps!

Comments
Submitted by teemak on Mon, 08/16/2010 - 15:24
Hello!
Thanks but I've a problem with it... it doesn't work!
Maybe there is a conflict with pathauto?
Submitted by teemak on Mon, 08/16/2010 - 15:56
Ok I found the problem. I can't put the pathauto directly in the URL.... Thx
Submitted by braindump on Tue, 09/21/2010 - 12:55
Thanks for sharing this such a wonderful post
Add new comment