欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

menu_per_role管理菜单的权限控制与菜单显示控制 有大用

shiping1 的头像

我的方法
admin/build/menu/item/1484/edit  

注意看上面的路径

通过设置 Restrict item visibility 来控制菜单项的显示或隐藏

 






menu_per_role管理菜单的权限控制与菜单显示控制  不指定

drupal水滴 , 2011/10/19 10:30 , drupal建站 » drupal模块 , 评论(0) , 阅读(1168)  |  |  

在drupal中,由于权限控制比较分散,不能细粒度的控制菜单的显示与否。例如设置角色1的administer users为true时,则不管怎么设置都会出现一个User Setting的菜单;再如设置administer nodes为true时,则不管设置create front_page content为true或false,该角色都可以创建该类型的内容(即可以访问该菜单)。
如何让用户不能访问create front_page content菜单呢?
一个比较简单的办法,就是结合使用/admin/user/permissions和Menu Per Role模组。前者控制系统的权限,后者用于控制菜单的权限来实现菜单是否予以显示。
1.首先在/admin/user/permissions启用access administration pages(用于控制管理菜单是否显示,是一个总开关),然后再设置相关模组的权限;
2.导航到/admin/build/menu-customize/navigation下,使用Menu Per Role模组控制导航菜单的显示:在Restrict access to only these roles下选择anonymous user(由于在/admin/user/permissions中设置了管理菜单只能由角色1访问,所以即使在这里选择anonymous user,anonymous user也是访问不了这个菜单的),从而实现了指定菜单的权限与显示控制。
使用该方法可以隐藏空的管理菜单,如Site configuration菜单。



http://drupal.org/project/menu_per_role

来自 http://www.majormoves.net/post/771/


I have a single menu item that I would like to show or hide based on user role.

Use case: I have a membership site with paid and free memberships. In the navigation menu, I want to show a link for users who do not have the "paid" role to the "Upgrade your account" page. There's no need to limit access; I simply want to show or hide the link.

I know I could make a separate menu and restrict access to that menu block by role, but is there an easy way to do the same for a single menu item link in an existing menu?

shareimprove this question
 

第一个正确答案 There is a way to do it without an extra module if the "Upgrade your Account" page is a view. Then you can limit access for that view to anonymous users and add the menu entry in that view.

shareimprove this answer
 
   
I use Panels, so I will add it in Panels. I much prefer this approach to installing an unstable module just for one link. –  Patrick Kenny Apr 28 '12 at 6:53
   
yeah, I usually take the same approach, "keep it simple" is a great mantra –  MotoTribe Apr 28 '12 at 14:55

第二个正确答案 You may try Menu per Role

This module allows you to restrict access to menu items1 based on user roles. It depends on the Drupal core menu.module—just activate both modules and edit a menu item as usual. There will be a new fieldset that allows you to restrict access by role. The fieldset also appears in the node edit form.

enter image description here

D7 release is not stable yet its 7.x-1.x-dev

shareimprove this answer
 
   
D7 is indeed dev, but it worked for me perfectly. –  Druvision May 24 '13 at 8:49

Another module solution to this that I recently found is Menu Item Visibility. While it is still in beta, it actually works in D7 right now, which I couldn't get Menu Item per Role to do. (I had to keep clearing the cache every time a user saved their profile to rebuild the menu.)

shareimprove this answer

来自
http://drupal.stackexchange.com/questions/29544/how-can-i-show-hide-just-one-menu-item-based-on-user-role

 
 
普通分类: