Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I limit access to menu by role in Drupal?

I'm building a Drupal site, and have added two custom menus to give two different groups of management links (some people will see one menu or the other, some will see both, and anonymous/low-level users will see neither).

The problem is, at the moment, all users can see the menus (but the menu items are not visible).

I'm trying to create a simple permissions module - and have created the administration forms which specify which menus are viewable by which role.

But I can't find a hook which lets me override the visibility of a particular menu - only the items.

So, how do I limit access to menu by role in Drupal now that I have a list of permissions in the database?

--

I have looked at Menu per Role and Menu Access. Unfortunately, these work at the item level and not on the menus directly.

like image 503
HorusKol Avatar asked Feb 21 '11 03:02

HorusKol


People also ask

Is menu an entity in Drupal 8?

Menu links are entities in Drupal 8, so they can be created using YAML Content the same as any other entity.

How do I set custom permissions in Drupal 8?

In Drupal 8, you can support dynamic permissions by referencing a function that will dynamically define those permissions. To define a callback that will dynamically generate permissions, all you have to do is to create a new root level key named permission_callbacks and list those callbacks.

What is the purpose of a role in Drupal?

Roles allow you to fine-tune the security and administration of Drupal. A role defines a group of users that have certain privileges as defined in user permissions. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on.


2 Answers

Each menu is in a block, and blocks can be set to be visible for given user group (access level). On drupal admin site: Structure/Blocks

like image 83
steve Avatar answered Oct 20 '22 00:10

steve


Menu Per Role module?

http://drupal.org/project/menu_per_role

like image 39
Kevin Avatar answered Oct 20 '22 00:10

Kevin