0

As the title says, I would give to members a way to choose their own role as required via radio buttons in their profile page. Any suggestion?

3
  • What research or possible modules have you found that might enable this functionality for you? – tenken Nov 17 '15 at 23:11
  • I spent half day looking for a module or a solution via php. The modules that I have found don't have this function but only allows to choose the role upon the registration: User Selectable Roles - Role Delegation - Auto Assign Role – Emanuele Nov 17 '15 at 23:18
  • If you'll try to type in google "how users can change their own role in drupal" or "allow users permission to change role drupal" or other possible query combination you'll see I'm right. This also applies to Drupal Answers... – Emanuele Nov 17 '15 at 23:41
1

You can do this with rules.

Event: After saving user profile
Conditonal: field has value
Action: Assign role to user

Something long these lines. You will need to create a new rule for each role unless you do some special field-value handling. You will also need to create a few checks in here to prevent the rule from re-assigning a role to a user.

3
  • Once I have create the rule how do I show the choose role radio buttons in the edit user account page? – Emanuele Nov 18 '15 at 1:28
  • How i can set the condition field has value? – Emanuele Nov 18 '15 at 11:31
  • Ok for those who want to know how to: First I've created two new boolean field in user account on/off single each called as the desired role. Then in rule: 1) Event: After saving and update user profile 2) Conditonal: Data comparison associated with the newly created field: value true 3) Action: add new role and remove another role. Create a new rule for every role. Finally show and hide the new fields in the edit account page with another rule. – Emanuele Nov 18 '15 at 16:04
0

The Role Delegation module should actually get you most of the way there. You would have to create a custom module to implement hook_form_alter() and change the role selection from multiple checkboxes to single radio buttons.

6
  • I'm using Single User Role to change the role selection to radio buttons and Auto Assign Role to allow the end user the option of choosing their unique role when they create their account. But I have't found anything that gives the opportunity to change the role inside the edit account page. – Emanuele Nov 18 '15 at 1:10
  • 1
    Role Delegation allows any user to change their role from their edit account page, as long as their role is given the permission to do so. Just check that your member role is allowed to manage the roles you want them to choose from. I tested it before I left my answer. – scronide Nov 18 '15 at 1:15
  • Thanks for link to Single User Role, by the way. That could come in handy. – scronide Nov 18 '15 at 1:17
  • I've tried with Role Delegation but it give to all the users with role-A the permission to change the roles for all others role-A users and not only to themselves... Maybe i'me wrong something? – Emanuele Nov 18 '15 at 1:23
  • 1
    Ah, right, my test role didn't have the View user profiles permission so it wasn't a problem. You can use Tab Tamer to disable the Roles tab it adds. – scronide Nov 18 '15 at 1:39
0

If there aren't too many roles, I would create a taxonomy with a term for each role. Then add a taxonomy term field to the User. Then I'd create rules for "user profile updated" to apply each 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.