I added an entityreference to the user's Account so users can select what group they want to join (checkboxes). They check it and via a rule, it automatically adds them to that group. I did this for multiple Group Types.

Now i need it to remove user (unsubscribe) from group if "unchecked". Right now users keep on getting added if they select a new checkbox, but they are not removed from the previous group.

How can the we remove them from the now unchecked group and add them to the newly checked rule?

I found how to delete all group subscriptions on one rule. However, it removes all subscriptions, even those not found in this entityreference. How can we limit to add/remove users from only these group types?

Willing to pay for support on this issue.

Thank you.

  • D7 ? is this functionality required when the user saves their account profile , as really Rules will only get you so far the only real way to get you exact what you need is custom code in a custom module but you need to provide more in question like where is the action take place, and screen shots of rules ect or you will not get an anwser that is right for you.
    – taggartJ
    Feb 1 '18 at 8:55
  • @TaggartJensen: why do you think "the only real way to get you exact what you need is custom code in a custom module"? IMO it's perfectly doable what OPer is asking for in a custom rule (so no need for a custom module ... Feb 1 '18 at 12:15
  • I personally don't like having Raw php in a rule but yes you can do it this way. and i admit i have done it this way too so go for it
    – taggartJ
    Feb 1 '18 at 22:00

I solved this. :)

I used the views_rules module to create a view that filtered a list of exactly what i needed (filtering the group type per user).

I then created a rule:

  • Before saving a user account

  • Condition if previous is equal to new saved (Negate). So it will only run if there are changes in the field in question.

  • Added View Loop i created. Add action > Delete entity mid from the view loop.

Done. This deletes or unsubscribes any unchecked boxes/groups.

Now to create any new memberships/subscriptions to selected groups...

I added condition...

-If field empty... do nothing


-Loop the field in question (gmem_created)

-Create new entity of type group membership

-Save a data value

Data: [gmem-created:group], Value: [account:field-yourgroup]

-Save a data value

Data: [gmem-created:user], Value: [account]

-Save entity

Entity: [gmem-created], Force saving immediately: true

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.