Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As the title suggests, it would be nice to limit the number of groups that a user can join at the same time.
For example .. if i want that one user can join only one group at time.
Comments
Comment #1
kristiaanvandeneyndeI can't code every use case I get a support request for, but It wouldn't be that hard to check for existing memberships:
As soon as I get some time on my hands, I'll add [user:group-memberships] to the available tokens so you can use Rules as well.
Comment #2
palyan CreditAttribution: palyan commentedHow can I prevent adding user to second group with this code? Is there some hook for adding or inviting user to a group?
Comment #3
kristiaanvandeneyndeIf a person joins a group in any way a GroupMembership entity is created and saved.
So you should be able to react on hook_entity_insert or hook_group_membership_insert and remove the newly created membership if they user has reached his threshold. Quite the overhead for something you'd want to prevent, not clean up after the fact, but it should work.