Pedro Posada | Setting up MENU_LOCAL_TASK for secondary tabs

Setting up MENU_LOCAL_TASK for secondary tabs

Posted on March 27, 2009 - 1:02pm
<< 14 of 46 >>

How to create secondary local tasks or secondary tabs, also called sub tab (second level) menu items.

It was not clear to me why it was necessary to create a MENU_DEFAULT_LOCAL_TASK in every tab level. In order to tell drupal's menu system to show primary and secondary local tasks, there is a need to create a default local task every time. The default local task points to the same page as the parent item but has a path longer by one element.

Parent path:
'admin'

Default primary local task path:
'admin/home'

Default secondary local task path:
'admin/home/home'

All three menu items go to 'admin' and all three show 'admin' on the address bar. Both local tasks can share the same page callbacks.

The code inside your hook_menu() would look something like this.

$items['cart/admin'] = array(
    'title' => 'Cart Administration',
    'page callback' => 'cart_admin_home_page',
    'access arguments' => array('access cart admin pages'),
  );
 
$items['cart/admin/home'] = array(
    'title' => 'Admin\'s Home',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
 
$items['cart/admin/home/home'] = array(
    'title' => 'Admin\'s Home',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );

Check out the following link to understand how to set up secondary tabs or secondary local tasks. This took me several hours to find and understand.

http://drupal.org/node/110773#comment-245960

Post new comment

The content of this field is kept private and will not be shown publicly.
Please solve the math question. This way we will know you are not a robot.