drupaltaxonomyorganic-groupsdrupal-rules

Drupal 7 (Un) Subscribing user to groups by (de)selecting taxonomy terms on profile edit page


I am using Drupal 7, rules, taxonomy terms (so the user can indicate his interests) and organic groups and I need people to subscribe and unsubscribe by selecting and deselecting taxonomy terms/interests on the profile page.

There is a OG reference field on the individual taxonomy terms so it is known which group relates to which taxonomy term and where the user needs to be subscribed to. By using “Fetch entity by id” i get the correct group when one selects a taxonomy term in Rules too.

AFTER SAVING NEW ACCOUNT:

When people sign up they can choose their interests (taxonomy terms) on the registration page and they are automatically subscribed to the corresponding groups. This works fine.

PROFILE EDIT PAGE:

But i cant get it to work when someone wants to unsubscribe (and subscribe again) on the edit profile page.

Any idea how it can be achieved that by checking / unchecking taxonomy terms on "after profile has been updated" the user is automatically (un)subscribed from the correct groups?

I have tried it with conditional rules (https://www.drupal.org/project/rules_conditional), but it seems to be abandoned (last beta is 2 years ago). There are around 8 groups, so I tried the module with a switch-case statement, but it displays an error message (indicating a bug).

Thanks for any thoughts on this!


Solution

  • Johan did it again!

    Much of the answer is in the Rules master Level up by Johan.

    Basically, one needs to create two RULES (one for adding people to a group and one for removing people from a group) which take 3 parameters: the unchanged user, the updated user and a taxonomy term (which is being looped through in the calling rule). The unchanged user list is compared with the updated user list and depending on the result, the user is subscribed or removed from the groups.

    In the first rule (event: "after account has been updated") you call the "add to group" rule and in the second rule you call the "remove from group" rule.