Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Azzor on
Hi all,
Is it possible to hide menu items that a user is not authorised to view? For example, a setup such that premium content is not visible to unregistered users. Currently with node_privacy_byrole, the node is still visible in the menu, but clicking on it gives the access denied message.
TIA,
Rohan
Comments
Try taxonomy access module
The node privacy byrole module lets you control permissions for individual nodes while the taxonomy access module lets you control permissions for entire categories. The taxonomy access module also has a patch included with it that will solve the problem you cite above, where users can still see the links to restricted content.
I tried taxonomy access, but
I tried taxonomy access, but I still get the same behaviour (the links being visible from the menu, but access denied when clicked on). I applied the patch taxonomy.patch during installation. Is there another patch i need to apply?
Rohan
Disable menu item
Just diable the menu item. Do you have the menu.module disabled?
menu.module is
menu.module is enabled.
With the menu item disabled, the menu item isnt visible to anyone, even to the administrator. The desired setup is such that a section of the menu is only visible to users who are logged on.
Rohan
I don't know
I don't know of any way to do that with the current menu.module. I think your best bet is to create a new block with some custom code.
I've created a patch to
I've created a patch to includes/menu.inc to solve this issue. I know that this is a bit of a hack, but it was the best i could come up with with my current knowledge of the code base. The patch can be found at http://undefined.homelinux.net/~zero/menu-visibility.patch for anyone interested.
Rohan
Another take at the same problem
I am part of a group migrating an existing community website to drupal. We had more or less the same problem. We do node access control with taxonomy_access, but the basic problem we wanted to solve, hiding menu items linking to inaccessible nodes, is the same. (We have different sub-communities with different access rights, in our case by taxonomy.) Our solution is a bit different, perhaps you can comment on this:
We modified menu.inc as follows:
And node_try_load is the following significantly truncated version of node_load:
Nobody of us is really familiar with the drupal code, so I would be happy to get some feedback on this by drupal experts.
And, by the way: Access control for menu items (especially based on node permissions - what point is there in displaying a menu item that leads to a forbidden node?) seems to me to be a very general problem that is not really addressed in drupal. Would it be sensible to post a feature request for this?
With best regards,
Martin