0

How would I go about modifying the "My account" text in the navigation menu, to link the title to a title callback?

My goal is to have "My account" say "My premium account," "My guest account," and so on when an applicable user is logged in. For most menu items, this would be easy to do with hook_menu_alter and a title callback.

But, hook_menu_alter doesn't seem to effect this menu item at all. Any ideas?

1

Drupal caches menu items, so if you're using hook_menu_alter you'll need to clear the menu cache to make your changes apparent. For your requirements, hook_menu_alter is no good anyway, as the menu has become dynamic!

My suggestion would be to use Menu Per Role. Create one menu that has each of your required menu titles in as seperate menu items (ie one menu containing three menu items; one for each type of account) and then restrict the visibility of those menu items to users with particular roles.

eg

  • My Account Links
    • My Account - only visible to standard users
    • My Guest Account - only visible to guest account holders
    • My Premium account - only visible to premium account holders

When set up correctly, this will only display one link per user (although when logged in as user 1 you will see all links).

1
  • That worked perfectly -- Thanks! I shoulda known there was a module that would solve the issue :p – anschauung Dec 2 '11 at 15:12
0

does each of them map to a user role? If so you would setup menu items for each of them and then use the "RESTRICT ITEM VISIBILITY" menu setting.

0

This can be done for instance within your theme, as the block will be shown for all users I assume. You'd create a function like so:

YOURTHEME_preprocess_block(&$variables) {
  global $user;
  if($variables['block']->delta == 'account' ) {
    $roles = array_values($user->roles);
    if (in_array('guest_role', $roles)) {
      $variables['block']->subject = 'My Guest Account';
    }
    if (in_array('premium_role', $roles)) {
      $variables['block']->subject = 'My Premium Account';
    }
    if (in_array('basic_role', $roles)) {
      $variables['block']->subject = 'My Account';
    }
  }
}
1
  • Thanks, but your code modifies the block title. I was looking to change the menu item. – anschauung Nov 2 '11 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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