protected function DemoGroup::addMembers in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.2 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.3 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.4 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.5 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.6 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.7 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 8.8 modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 10.3.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 10.0.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 10.1.x modules/custom/social_demo/src/DemoGroup.php \Drupal\social_demo\DemoGroup::addMembers()
- 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 185 
Class
- DemoGroup
- Class DemoGroup.
Namespace
Drupal\social_demoCode
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);
    }
  }
}