2

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?

1 Answer 1

4

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).

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.