I have a custom modules name "Employee Entry" and i want that module show only some of the users under a specific role. Like if i have a role office then i want there is few people who can access the content of that module. There is a by default option to give access to whole role but there is no option to give access for specific users.

  • What specifically do you want to give/limit access to? A listing page, or individual node/entity pages? – Jaypan Nov 28 '16 at 10:14
  • i want to give limit access to this url example.com/users-add-form – Sumit Aggarwal Nov 28 '16 at 10:15
  • This form is basically for data entry and i want in a specific role only few users assigned for data entry – Sumit Aggarwal Nov 28 '16 at 10:16
  • Creating a new role and assigning the users/access to that would be the best solution – Clive Nov 28 '16 at 10:45
  • but i need only one role and give specific permissions to the specific users under this role – Sumit Aggarwal Nov 28 '16 at 10:50

The correct approach here would be to implement hook_permission to define permissions/a set of permissions to give your user roles specific access.

The Example module has some good info on how to use and validate permissions with hook_permission in your code.

If you want to restrict certain users, the easiest approach is to create an additional role with those specific things and assign the desired users to that role.

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.