How to hook into group role insert/update?

Created on 12 May 2017, about 8 years ago
Updated 26 March 2021, about 4 years ago

Hello,

I can see that the grolesync module is not working and am trying to figure out how to hook into the process of adding a group role so that I can then add a matching Drupal role. I know how to do everything except hook into the first step (when a user gives a member a particular role - or when a role is assigned). I tried hook_entity_update and it runs but the entity passed is the GroupContent entity and it does not appear that the new roles assigned are in that object. I also tried hook_group_role_update but I do not think that is actually a 'thing'.

If this is even possible, what do I need to call to

1) hook into the process of adding a group role to a group member (or updating roles)
2) get the new/changed role information

Any help would be greatly appreciated.

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Group (group)

Created by

πŸ‡ͺπŸ‡ΈSpain bletch

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Any ideas if anything changed in D10? This hook doesn't seem to get triggered adding content in group.

  • πŸ‡ΊπŸ‡ΈUnited States dureaghin Albany, NY

    Drupal 10 version:

    function  hook_group_relationship_update(GroupRelationshipInterface $entity) {
      // Act only on specific Group type memberships.
      if ($entity->bundle() == 'GROUP_TYPE-group_membership') {
        $new = array_column($entity->group_roles->getValue(), 'target_id');
        $old = array_column($entity->original->group_roles->getValue(), 'target_id');
        sort($new);
        sort($old);
        // If roles changed.
        if ($new != $old) {
           // Act on the role change here.
          \Drupal::messenger()->addMessage('Act on the role change here');
        }
      }
    }
Production build 0.71.5 2024