Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to use hook_menu_alter to change the title and weight of the node edit tab, but only for the group node type. However, the following (which is inspired by http://www.nicklewis.org/node/999) doesn't work.
$node = menu_get_object();
if (og_is_group_type($node->type) == 'TRUE') {
$items['node/%node/edit']['title'] = t('Group settings');
$items['node/%node/edit']['weight'] = 6;
}
It seems that the $node variable gets set the first time and simply doesn't change after that. It can be seen from this code:
$node = menu_get_object();
$items['node/%node/edit']['title'] = $node->type;
If the first page I watch after clearing the cache is of type 'page', then page is output on every node type. How can that be? Any idea is appreciated.
Marcus
Comments
Comment #1
awolfey CreditAttribution: awolfey commentedWe can't see your complete code, but you need to make sure the hook_menu_alter is calling another function to get the $node, rather than loading the node in the hook, where it will only be done when the menu is rebuilt.
For example, here I'm changing the title of the "View" tab when the node type is "vehicle".
Comment #2
DieterWeb CreditAttribution: DieterWeb commentedthis solution won't work, in fact it doesn't change anything if you use another function or set the menu items in the hook. if you think about it this makes sense, because if the hook is cached, it won't be called again, therefore your extra function won't get called too. i've tried the following to verify it (it tries to disable a menu item of the bbb module only if the node type is "classroom"):
after clearing all caches, everything works as expected and the menu item is disabled if i go to a classroom node page. now theres two ways to check if its really dynamic or if it is coming from cache. first, just access another page with these menu items with a different node type, or change the node type "classroom" to something else in the code. now, without clearing the cache, access the page, and you will see, that the data comes from cache. so even the node type is not classroom, the menu item is disabled, or if you change the node type name to something else, and refresh the classroom node page, it stays disabled.
i am still looking for a solution for this, if someone has any idea, it will be greatly appreciated.
Comment #3
awolfey CreditAttribution: awolfey commentedYes, of course it doesn't work! I didn't test it thoroughly. Thanks for the catch. I'll reply again when I have a soution.
Comment #4
e_oliver CreditAttribution: e_oliver commentedYeah actually you have to access the title callback property, not the title. Then you can do something like this: