0

I want to add a Login link in the user menu. When I give it the path 'user/login', I get the message: The path 'user/login' is either invalid or you do not have access to it.

If I give it a path of 'user', it works. However, that's not the path I want, because it will still be visible to the logged-in user.

If I give it a full path, http://mysite.com/user/login, it works BUT isn't hidden from the logged-in user. Puzzling.

Any ideas? I am pretty sure I could use a module to handle this, but it seems like overkill.

  • You cannot see user/login path after logged in. In fact there is nothing a logged in user can do. – niksmac Jun 11 '13 at 2:42
  • Right, but I can't put that path into the User menu. I get the error above when I enter it as a link. – mollyavalon Jun 11 '13 at 3:21
  • If you use proper menu or drupal l() function to print the link, it will not be there for logged in users. Means it will follow Drupal permissions. – niksmac Jun 11 '13 at 3:26
7

If you are using the Sub-pathauto module simply:

  1. Disable the subpathauto module.
  2. Add your menu item(s) for user/login.
  3. Re-enable the subpathauto module.
2

Thank you to everyone who answered. I was not asking about whether or not the login link was visible, but was instead asking how to enter the user/login path on the user menu or in the URL aliases without getting an error.

I solved it by using the path user/login? instead of user/login. So simple, so much time wasted.

  • wow, too clever. It worked and can't be anymore simple. – Kevin Siji Jan 7 '15 at 12:39
1

How about wrapping it in a conditions like these?

if (user_is_logged_in()) {
  // Do something.
}

or

if (user_is_anonymous()) {
  // Do something.
}

A useful link - https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_menu_site_status_alter/7

  • Thanks for the hint, so I no longer user !user_is_logged_in() anymore :) – kwoxer Jun 30 '16 at 13:49
1

That error message is show from the form validation handler used by the form that allows you to add a menu item, or edit it; it calls drupal_valid_path(), which contains the following code.

return $item && $item['access'];

As @Nikhil M said in his comment, logged-in users don't have access to that menu item, which means $item['access'] is FALSE.

The only way I found to add that link was first creating a path alias (e.g. user-login) to /user/login, and then using the path alias when creating the menu item.

screenshot

Apparently it works.

screenshot

Once logged in, the menu item doesn't appear.

screenshot

I have also tried with a different menu (e.g. the Main menu) and it works.

screenshot screenshot

At first, it seemed not to work, since the link was not shown when I logged out. To see the login link, I had to clean the Drupal cache, and refresh the page from Firefox after logging out.

  • This is a great-looking solution, and I was hopeful, but the URL alias is giving me the same error message when I enter /user/login, so I can't make the alias either. – mollyavalon Jun 11 '13 at 15:25
  • I am not having a problem with whether it shows up if you are logged in or not. I know it will work if I can just get either the menu or the URL alias config to accept user/login. – mollyavalon Jun 11 '13 at 15:26
  • I didn't have any problem for the path alias to accept user/login as existing system path of the alias. If that makes any difference, I used the user 1 account to set the path alias. – kiamlaluno Jun 11 '13 at 22:13
0

One of my colleagues came up with a simple solution that I'm sharing in case it helps others. "Basically, you can't edit an existing menu item that links to user/login, you have to create a whole new one. I did that and it's working now!"

So you can create a menu item with the path in question (user/login), but you'll never be able to edit it. If you want to change the text down the road,create a new menu item and delete the old.

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.