You are here

public function OgMembership::setRoles in Organic groups 8

Sets the group's roles for the current user group membership.

Parameters

\Drupal\og\OgRoleInterface[] $roles: The array of OG roles to set.

Return value

\Drupal\og\OgMembershipInterface The updated OG Membership object.

Overrides OgMembershipInterface::setRoles

2 calls to OgMembership::setRoles()
OgMembership::addRole in src/Entity/OgMembership.php
Adds a role to the user membership.
OgMembership::revokeRoleById in src/Entity/OgMembership.php
Revokes a role from the OG membership.

File

src/Entity/OgMembership.php, line 282

Class

OgMembership
The membership entity that connects a group and a user.

Namespace

Drupal\og\Entity

Code

public function setRoles(array $roles = []) : OgMembershipInterface {
  $roles = array_filter($roles, function (OgRole $role) {
    return !($role
      ->getName() == OgRoleInterface::AUTHENTICATED);
  });
  $role_ids = array_map(function (OgRole $role) {
    return $role
      ->id();
  }, $roles);
  $this
    ->set('roles', array_unique($role_ids));
  return $this;
}