I've searched for hours but I can't find a good answer on how to alter the type of a menu item to local task (tab).

The private messages 7.x module (when aided by privatemsg_filter) exposes the following tabs (local tasks):

  • Inbox (/messages)
  • Sent Messages (/messages/sent)
  • All Messages (/messages/list)

There is a 4th menu item (/messages/new) which is currently a MENU_LOCAL_ITEM and I want to make it a local task as well. But how? And what is the best way?

2 Answers 2


The following hack worked, to create a new local task item with definitions identical to the original menu item except it's a local task. But is it the optimal way?

 * Implements hook_menu().
function MOMODULE_menu() {
  $items['messages/newmessage'] = array(
    'title'            => 'Write new message',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => array('privatemsg_new', 2, 3, NULL),
    // 'file'             => 'privatemsg.pages.inc',
    'access callback'  => 'privatemsg_user_access',
    'access arguments' => array('write privatemsg'),
    'type'             => MENU_LOCAL_TASK,
    'weight'           => 5,
    'menu_name'        => 'user-menu',

  return $items;
  • 2
    You should use hook_menu_alter instead. E.g.: `$items['messages/newmessage']['type'] = MENU_LOCAL_TASK;
    – znerol
    Commented Nov 11, 2013 at 19:51
  • 1
    @znerol This is the correct answer. I was just about the write an answer to recommend that. You'd better write this as answer an get some points.
    – Elin Y.
    Commented Nov 11, 2013 at 20:01
  • Thanks @znerol, Can I also add a css class to the tab using this hook? (if I have the menu_class module installed)
    – Druvision
    Commented Nov 11, 2013 at 20:04
  • @Druvision: AFAIK at least on Drupal 7 you do not need to have any third-party modules installed in order to inject attributes to menu-items. $items['messages/newmessage']['options']['attributes']['class'][] = 'my-class'; should do the trick.
    – znerol
    Commented Nov 11, 2013 at 20:19

Thanks @zenrol, here is a code example for the correct answer:

function MYMODULE_menu_alter(&$items) {
  // Make the privatemsg new link a tab
  $items['messages/new']['type'] = MENU_LOCAL_TASK;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.