4

I am trying to change the title ( tab text ) of the standard Drupal menu local task tabs 'View' and 'Edit'. I want them to reflect the content type of the current node. So on the page node/1234 ( which is a blog node, say ) I want the View tab to say 'View blog' etc.

I can change the text using :

$items['node/%node/view']['title'] = 'View blog';

in a hook_menu_alter() function, but I can't seem to get hold of the node itself to test what content type it is to vary the text. The arg() function doesn't return anything within the hook_menu_alter() function for some reason ?

How do I do this ?

Thanks

0

2 Answers 2

0

hook_menu() implementations are cached so aren't executed for every page (can you imagine how bad that would be for performance?)

You can use the title callback property from hook_menu() to evaluate a title on each page load, e.g.

$items['node/%node/view']['title callback'] = 'MYMODULE_title_callback';
$items['node/%node/view']['title arguments'] = array(1);

...

function MYMODULE_title_callback($node) {
  if ($node->type == 'foo') {
    return 'bar';
  }
  else {
    return 'baz';
  }
}
3
  • Thanks Clive. I also just found the answer here drupal.stackexchange.com/a/53345/10957.
    – elb
    Mar 7, 2013 at 10:40
  • Cool, I shall mark this question as a duplicate of that one :)
    – Clive
    Mar 7, 2013 at 10:41
  • It may also be worth mentioning hook__menu_local_tasks_alter(), which lets you alter local tasks more generally. Mar 7, 2013 at 11:56
-1

You can try Tabname Tweaker module.

This module allows admins to override the name of the 'View' tab on node pages. Useful for Organic Groups, where the normal 'View' tab serves as an overview or landing page rather than a specific piece of content.

This module allow to change and override the View and Edit tabs

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