9

I'm trying to add an extra tab to the node 'view' and 'edit' tabs.

My module is enabled fine and I have cleared cache, but my new tab doesn't appear. What am I missing?

/**
* Implements hook_menu().
*/
function add_performance_menu() {
  $items = array();

  $items['node/%node/performance'] = array(
    'title' => 'Add a performance',
    'page callback' => 'add_performance_action',
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

/**
* Page callback.
*/
function add_performance_action() {
  return t('Hello');
}

closed as off-topic by Yusef Mohamadi, Shawn Conn, Scott Joudry, Krishna Mohan, No Sssweat May 18 '16 at 4:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Yusef Mohamadi, Shawn Conn, Scott Joudry, Krishna Mohan, No Sssweat
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Does the route work? If you go to '/node/1/performance', do you get "Hello" back? – Les Lim Nov 10 '13 at 21:46
  • Good point. No it just displays the node as usual. – pushka Nov 10 '13 at 22:18
  • 4
    There's nothing wrong with the code you posted, so go through the usual checks: look at the filename of your module file for typos, actually look at your cache tables to make sure they're clearing, etc. – Les Lim Nov 10 '13 at 22:37
  • 1
    Hey thanks - reassuring to know it wasn't the code. In the end, I got it working by disabling and re-enabling the module. Maybe because the router table is updated on enabling? Anyway... it works now. – pushka Nov 11 '13 at 9:22
0

When you change the hook_menu you don't have to 'clear cache' but 'rebuild menus'.

  • rebuild menus is enough, but clear cache includes rebuild menus. – sanzante Nov 17 '14 at 10:42
0

Your code looks good but Remember to clear your Drupal caches at admin/config/development/performance after every change to your hook_menu above.

The alternative that comes to mind,would be to use hook_menu_local_tasks_alter, because the menu item we want to use may be already exists.

You can also try this i hope it will help you:

/**
* Implements hook_menu().
*/
function add_performance_menu() {
  $items = array();
  $items['node/%node/performance'] = array(
    'title' => 'Add a performance',
    'access callback' => 'your_module_access_check',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}
function your_module_access_check($node) {
  if ($node->type == 'page') {
    return TRUE;
  }
  return FALSE;
}

Thanks

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