You are here

protected function DemoGroup::addMembers in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  2. 8.2 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  3. 8.3 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  4. 8.4 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  5. 8.5 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  6. 8.6 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  7. 8.7 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  8. 8.8 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  9. 10.3.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  10. 10.0.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  11. 10.1.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
  12. 10.2.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()

Adds members to a group.

Parameters

array $members: The array of members.

array $managers: A list of group managers.

\Drupal\group\Entity\GroupInterface $entity: The GroupInterface entity.

1 call to DemoGroup::addMembers()
DemoGroup::createContent in modules/custom/social_demo/src/DemoGroup.php
Creates content.

File

modules/custom/social_demo/src/DemoGroup.php, line 188

Class

DemoGroup
Class DemoGroup.

Namespace

Drupal\social_demo

Code

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);
    }
  }
}