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.

Comments

bletch created an issue. See original summary.

jwjoshuawalker’s picture

Version: 8.x-1.0-beta5 » 8.x-1.x-dev

I know this is an old issue, but for anyone else looking for answers to this, mirroring what this module does in: GroupContent::postSave, you can do it via a hook, e.g. :

hook_group_content_update(Drupal\Core\Entity\ContentEntityInterface $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.
    }
  }
}