3

I am pretty new to Drupal. I am using Profile2 so that the user can select there own user role. So say I have a profile page with some checkbox items like

  • Automotive
  • Computer
  • Garden
  • etc

How would I add a condition or data comparison in Rules to say, If Automotive is selected/checked, set user role to that role? I also need to be able to select multiple checkboxes to get multiple roles.

Any suggestions?

1 Answer 1

3

Part 1 - Make it work for a single selection and related role

Create a rule which looks like so:

  1. Rules Event: After saving user profile.
  2. Rules Conditions (both conditions must be satisfied):

    • entity has field (with the field corresponding to (eg) "Automotive".
    • data comparison to check if "Automotive is selected/checked".
  3. Rules Action: : Assign role to user (for the role related to "Automotive").

You could create a similar rule for each possible combination of checkboxes and roles to be assigned. Or continue as detailed in Part 2 to further enhance your rule from Part 1 so that you end up with a single rule for all possible combinations.

Part 2 - Make it work for other possible combinations

To also make it work for other possible combinations, and because of the fact that a Rules action cannot contain "conditions", you basically have 2 possible approaches:

  • Create a similar rule (as in Part 1) for each possible combination.
  • Use the Conditional Rules module to enhance the Rules Action in the above rule to alter the flow, using either Conditional (if/else) of Switch logic. Be aware: this module only has a beta release for D7, though it's used in over 8K sites (which makes it seem like a pretty robust module though).
1
  • 1
    Wow, thank-you so much. This information is very helpful! Commented Feb 18, 2016 at 0:21

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.