I have a multiple roles in my site, let's say I have role A, B, C, D.

I want users to be able to choose which role a user wants when logging in. And then the user should only be able to access the content for the selected role (even if the user has multiple roles).

Any suggestions about how to implement this?

  • I am newbie in Drupal but this kind of stuff I used to do in PHP by creating a table set of users and roles. In Drupal Database there is users table and roles table linked with each other, but if you can hack and create a new tables for each roles which has users and roles as columns then its easily achievable, but you end up having lots of duplicate entries.
    – user12947
    Commented Oct 26, 2013 at 7:55

2 Answers 2


Changing roles would probably require the permission "Administer permissions" so it could be hard. There's a module that does what you want, but it would probably require some modification: https://drupal.org/project/roleswitcher

There's also the Masquerade module (https://drupal.org/project/masquerade) which offers the ability to switch user account - which may be useful depending on your needs.


Add a profile field

Add a field, say "Desired User Role", to the user profile.

Create a 1st Rule

  • Rules Event: After user login.
  • Rules Actions:
    • Remove role A, B, C and D for user.
    • Perform a redirect to user/uid/edit (to show the user's profile in edit mode).
    • Set a Drupal message like "Select your desired User Role".

Create a 2nd Rule

  • Rules Event: After updating a user profile.
  • Rules Conditions (AND):
    • User ID of the user for which the profile is updated is current site user (to not block user profile edits by other authorized users).
    • Field Desired User Role (unchanged) is not eaqual to Desired User Role.
  • Rules Action (using the Conditional Rules module to allow conditions to be contained within Rules Actions):
    • If selected Desired User Role=A then grant access to role A.
    • If selected Desired User Role=B then grant access to role B.
    • If selected Desired User Role=C then grant access to role C.
    • If selected Desired User Role=D then grant access to role D.

This rule also facilitates swapping from one role to another (without forcing an indermediate logout/login). If that's NOT what you want, then this rule needs further refinement. I.e. add an extra Rules Condition to also check that no Desired User Role (unchanged) was selected before trying to update it.

Note: for this to work, a user can have multiple "other roles", but they should not overlap with A, B, C or D.

Your Answer

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

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