How to add a tab to the node in Drupal

11 Feb · by Tim Kamanin · 1 min read

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

Required for comment verification



Android

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

Reply · 7 years, 10 months ago
braindump

Thanks for sharing this such a wonderful post

Reply · 7 years, 10 months ago
teemak

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

Reply · 7 years, 10 months ago
teemak

Hello! Thanks but I've a problem with it... it doesn't work! Maybe there is a conflict with pathauto?

Reply · 7 years, 10 months ago