I need show a menu link that links to /node/add/article for anonymous users but they don't have access to that page.

I have seen solutions like:

  • Using an absolute URL (that way Drupal does not check user access).
  • Alter the menu access callback but I do not really want to give them access just to print the link.

Are there any other solutions?

  • What happens when an anonymous user follows the link? They see a forbidden page? User login? – sanzante Nov 15 '17 at 13:41
  • Anonymous user will be redirected to user login. – Sandra Nov 15 '17 at 14:05

In your case you can use two menu entries in the same menu:

  • One pointing to /node/add/article.

  • Another one pointing to /user/login.

First link is only visible to registered users, because anonymous users don't have permissions to add articles.

Second link is only visible to anonymous users because registered users don't have permissions to see the user login page (because they are already logged in).

The result is a menu with only one menu entry. Registered users see first link, anonymous see only second one.

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.