Trying to update a group membership to add an additional role, but cannot find any help on how to do this.
I want to add the role of "manager" to all owners of "client" type groups, using the following code:
// Get the group owner
$owner = $group->getOwner();
// Get the membership details of the owner
$membership = $group->getMember($owner);
// Get the roles of the owner
$roles = $membership->getRoles();
// Check whether the owner has manager role
if (!isset($roles['client-manager'])) {
// No, so add the manager role to the membership
// >>> The following doesn't work, but I hope you get the idea <<<
$manager = new GroupRole();
$membership->addRole($manager);
$membership->save();
}
Any help or advice with this problem appreciated.
I was using hook_group_user_roles_alter(), but this has been removed in the latest release (8.x-1.0-beta5), so now need to implement a db update function to set it permanently.