tags:

views:

41

answers:

1

When an anonymous user comes to the site, the last item in the Primary Links needs to say Login. However, if they are logged in, it needs to say Account.

Whats the easiest way to achieve this in code?

+3  A: 

I accomplish this by using the me aliases module to generate one single path for the account page of the logged in user (e.g. user/me) and adding both user/me and user/login to the menu.

If you wanted to do this programmatically, you'd use menu_link_save():

$account = array(
  'link_path' => 'user/me',
  'link_title' => t('Account'),
  'weight' => 100,
);

$login = array(
  'link_path' => 'user/login',
  'link_title'=> t('Login'),
  'weight' => 100,
);

menu_link_save($account);
menu_link_save($login);

Due to the way Drupal handles menu permissions, a logged in user will not see Login (logged in users do not have access to user/login) but will see Account, and logged out users will see Login but won't see Account (anonymous users do not have access to user/me).

Mark Trapp
Wow, that was a lot easier than I thought it would be. Never heard of that module before. Thanks.
Kevin

related questions