Add and Remove roles from member API

Created on 27 July 2023, over 1 year ago
Updated 12 September 2023, about 1 year ago

Problem/Motivation

At the moment there are not APIs to add or remove a role from a member.

I can add a role doing: $group_relationship->set('group_roles', [role_ids]);
Before that, I need to loop through the member roles and add all the existing role ids in an array and then add the new role.
Then save the Group relationships

$memeber = $group->getMember($account);
$existing_roles = $member->getRoles();
$g_relationship = $member->getGroupRelationship();
if (!isset($rexisting_roles[$new_role_id)) {
  $updated_roles = [];
  $updated_roles = $new_role;
  foreach($existing_roles as $existing_role) {
    if ($role->getScope() == 'individual') {
      $updated_roles[] = $existing_role->getOriginalId();
    }
  }
  $g_relationship->set('group_roles', $updated_roles);
  $g_relationship->save();
}

Is there a better way of doing it?

Feature request
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

🇮🇹Italy Vincenzo Gambino

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

Comments & Activities

Production build 0.71.5 2024