ECA event for joining Group

Created on 6 April 2025, about 1 month ago

Problem/Motivation

Hello! I'm not sure what ECA event is triggered for a user joining a Group (I'm using Group module https://www.drupal.org/project/group )? Basically, when a user clicks the Join Group link, I want to automatically assign that user to a specific role in the Group. I don't see any events related to Group (I only see Actions for Groups as I've the group_action module installed). I'm not sure what event I should use to start the ECA model. I'm currently using: Drupal 11.1.5, Group 3.3.0, and ECA 2.1.6 ( https://www.drupal.org/project/eca ). Thank you very much for any help/suggestion!

💬 Support request
Status

Active

Version

2.1

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ikam
  • 🇩🇪Germany jurgenhaas Gottmadingen

    When a user joins a group, the group module creates a group relationship entity. That entity contains a reference to the group and to the user. You can use the event when a new content entity is being created of that type "Group Relationship", as this is what's happaning here.

  • Thank you Jurgen - I was able to create a ECA model that would do the following:

    When a user joins a group (either user clicks "Join Group" or the group admin adds the user to the group), the user will be automatically assigned a group role (in my case, the 'member' group role). I've attached the ECA model for anyone interested.

    Some notes on my model:

    • I used the Insert Content Entity event with custom properties: Group Relationship - Group membership
    • I had to switch to the super user id=1, otherwise the current user (i.e. the user self joining a group) might not have privileges to add a group role for himself.
    • The Group Relationship only has a token called 'label', which holds the username of the user joining the group. I had to use the Entity Load action using the username to find the actual user entity. This user entity is needed in subsequent Action "Group - Update User Membership"
    • Before updating the group membership, I added a Condition to check if the Group Relationship already has at least 1 group role, so that the Group - Update User Membership action will not over write any assigned group roles for the user. The purpose of my model is to assign a default group role only if the group relationship does not have any group role(s) assigned to the user joining the group.

    Thank you very much for your help and suggestion Jurgen!

  • 🇩🇪Germany Istari

    Wouldn't this be a good action for ECA Group ?
    I could imagine that a single action would lessen the whole process from multiple conditions and actions to one central action.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    @ikam well done. There may be some shortcuts possible. But getting into ECA by building something that works first, and then optimizing over time, is perfect as we all learn so much with that approach over time.

    @mysdiir creating an action doing all that all at once may have to be very opinionated. It's very likely that everybody who needs something like this will have slight variations to it. That's why ECA is built with granular, small components (lego blocks) that can be combined in any possible way to get to exactly what a specific user requires.

    The flip side of that is, that models have to be built with more steps than you may have expected beforehand. But certainly less steps than writing custom code would have taken.

    But there is a solution to that, too: build a model in a generic way and publish that as a recipe, so that not everybody has to do the same (or similar) steps themselves over and over again. That saves everybody time and effort, and still everybody can modify such models towards their own requirements, if they are slightly different.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024