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?

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
    Wow, thank-you so much. This information is very helpful! – Ryan Hepple Feb 18 '16 at 0:21
  • 1
    @Ryan Hepple, if this answer solved your problem/question, please accept the answer by clicking on the checkmark icon. – No Sssweat Feb 18 '16 at 0:25
  • Stupid question. How do I get the field corresponding to Automotive? I got something like profile2:user:profile-service-provider:field-services:0 for my data selector. Theres options from 0-3. Im not quite sure how this works. – Ryan Hepple Feb 18 '16 at 2:47
  • @RyanHepple : please post your last comment as a new question (if you still didn't find the answer). Possibly with a link to this question as a kind of followup question. – Pierre.Vriens Mar 18 '16 at 16:00

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.