protected function addMembers(array $members, array $managers, GroupInterface $entity) {
    foreach ($members as $account_uuid) {
      $account = $this->userStorage->loadByProperties([
        'uuid' => $account_uuid,
      ]);

      if (($account = current($account)) && !$entity->getMember($account)) {
        $values = [];
        // If the user should have the manager role, grant it to him now.
        if (in_array($account_uuid, $managers)) {
          $values = ['group_roles' => [$entity->bundle() . '-group_manager']];
        }
        $entity->addMember($account, $values);
      }
    }
  }
protected function addMembers(array $members, array $managers, GroupInterface $entity) {
    foreach ($members as $account_uuid) {
      $account = $this->userStorage->loadByProperties([
        'uuid' => $account_uuid,
      ]);

      if (($account = current($account)) && !$entity->getMember($account)) {
        $values = [];
        // If the user should have the manager role, grant it to him now.
        if (in_array($account_uuid, $managers)) {
          $values = ['group_roles' => [$entity->bundle() . '-group_manager']];
        }
        $entity->addMember($account, $values);
      }
    }
  }
protected function addMembers ( array $ members , array $ managers , GroupInterface $ entity ) { foreach ( $ members as $ account_uuid ) { $ account = $ this -> userStorage -> loadByProperties ( [ 'uuid' => $ account_uuid , ] ) ; if ( ( $ account = current ( $ account ) ) && ! $ entity -> getMember ( $ account ) ) { $ values = [ ] ; // If the user should have the manager role, grant it to him now. if ( in_array ( $ account_uuid , $ managers ) ) { $ values = [ 'group_roles' => [ $ entity -> bundle ( ) . '-group_manager' ] ] ; } $ entity -> addMember ( $ account , $ values ) ; } } }
Adds members to a group.

@param array $members
The array of members.
@param array $managers
A list of group managers.
@param \Drupal\group\Entity\GroupInterface $entity
The GroupInterface entity.
Adds members to a group .