How do I create secondary local tasks with hook_menu in Drupal 7?
For instance, if I wanted to add a new tab to a node, that presented multiple tasks beneath it?
- View
- Edit
- Update
- Price
- Photo
- Person
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou should use a combination of the MENU_LOCAL_TASK
and MENU_DEFAULT_LOCAL_TASK
types:
$items['node/%node/update'] = array(
'title' => 'Update',
'page callback' => 'price_callback_function',
'access arguments' => array('access args'),
'type' => MENU_LOCAL_TASK // This adds the 'Update' tab to the node path
);
$items['node/%node/update/price'] = array(
'title' => 'Price',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10
);
$items['node/%node/update/photo'] = array(
'title' => 'Photo',
'page callback' => 'callback_function',
'access arguments' => array('access args'),
'type' => MENU_LOCAL_TASK // This adds another tab under 'Update'
);
// etc...
You can control the order of the tab using the weight
key in your menu item.
Don't forget to clear Drupal's cache once you add this to hook_menu()