How to add a tab to the node in Drupal

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, 2010-08-16 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, 2010-08-16 15:56

Ok I found the problem. I can't put the pathauto directly in the URL.... Thx

Submitted by braindump on Tue, 2010-09-21 12:55

Thanks for sharing this such a wonderful post

Submitted by Android on Tue, 2013-02-19 08:05

Thanks for sharing.I really appreciate it that you shared with us such informative post,great tips and very easy to understand.

Add new comment

You are here