You are here

protected function TrainingContentTrait::addGroupRoleForUser in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x tests/src/Functional/TrainingContentTrait.php \Drupal\Tests\opigno_learning_path\Functional\TrainingContentTrait::addGroupRoleForUser()

Adds user group role.

2 calls to TrainingContentTrait::addGroupRoleForUser()
TrainingEditInterfaceAccessTest::testAccessEditPageTraining in tests/src/Functional/TrainingEditInterfaceAccessTest.php
Tests which users can subscribe and start a training.
TrainingEditInterfaceTest::testTrainingInterfaceAccess in tests/src/FunctionalJavascript/TrainingEditInterfaceTest.php
Tests Training Interface Access.

File

tests/src/Functional/TrainingContentTrait.php, line 186

Class

TrainingContentTrait
Trait TrainingContentTrait.

Namespace

Drupal\Tests\opigno_learning_path\Functional

Code

protected function addGroupRoleForUser(Group $group, $user, $roles) {

  /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
  $plugin = $group
    ->getGroupType()
    ->getContentPlugin('group_membership');
  $group_content = GroupContent::create([
    'type' => $plugin
      ->getContentTypeConfigId(),
    'gid' => $group
      ->id(),
    'entity_id' => $user
      ->id(),
    'group_roles' => $roles,
  ]);
  $group_content
    ->save();
}