9

I have a website that uses Private module in order set the access to the content, and of course some of my pages have menu items. Now if I set a page to be private, only users with proper permission could see that, which is great and what I wanted.

But I am having a bit of issue with the menu items, they disappear if the content assigned to them are not public (ie the page assigned to them is Private), this is OK but I would like to be able to still show those items in the navigation, so if user clicks on them, it will take them to the login page asking them to enter their details in order to see that particular page.

So basically I would like to change the behavior of the menu items the way that they will always be visible to anonymous and registered members of the website but when you click on them, you will be either able to see the page (if you are logged in) or be redirected to the login page (if anonymous)

I found this solution which is not the best one for me since I have many pages like that so I am looking for a better approach. I have even tried Menu item visibility module but that didn't help either!

How do I achieve this please?

Luca

1

2 Answers 2

4
+50

Your problem is quite common.

Here is discussion how to implement such trick in Drupal 6 and 7 and 8: http://drupal.org/node/300607

Drupal 6 (and 7) removed the ability to display menu items the user doesn't have access to. However, in some cases it is desirable to show a menu item even though the user doesn't have access to the menu item. For example, if you use an authentication mechanism that tries to acquire authentication when a 403 would be displayed, you still want to display the menu item so that users get a chance to provide credentials to log in.

Solution for Drupal 7 can be found here: http://drupal.org/node/300607#comment-4450062

If you prefer ready module - you can download it here https://github.com/systemseed/always_visible

1
  • Thank you very much. Wish they had this option built-in Drupal
    – Luca
    Dec 4, 2012 at 19:21
1

I had a similar situation where pages had to appear in the menu system, but the content should only appear to logged in users. The final solution was very simple, and continues to work.

Instead on controlling content access, the node template checks if the user is logged in. If so, it displays the content. If not, text appears with links to log in or register.

They are not automatically redirected, so if that is critical then this is not the solution.

The code in a nutshell:

<?php  
global $user;       
if ( $user->uid ) :
print render($content);
// or in some situations, display a view;
else : 
print 'Please <a href="/user/login">log in</a> or <a href="/user/register">register</a> etc etc.'
endif; 
?>
2
  • Thank you but that would not be a good solution for many reasons, one that I am using a different type of template system and I want to have content access on so when listing content ie in Views, that would respect the access.
    – Luca
    Nov 29, 2012 at 6:38
  • ah, yes. I hope you find an answer. It seems like it would be a pretty common use-case.
    – keva
    Nov 29, 2012 at 14:25

Your Answer

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

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