You are here

function og_test_entity_insert in Organic groups 8

Implements hook_entity_insert().

File

tests/modules/og_test/og_test.module, line 33

Code

function og_test_entity_insert(EntityInterface $entity) {

  // In order to test if it is possible to use an hook_entity_insert()
  // implementation to override the user membership that is automatically
  // created in og_entity_insert() we will create our own membership here, if
  // the entity's label matches the one created in the test.
  // @see \Drupal\Tests\og\Kernel\GroupManagerSubscriptionTest
  if ($entity
    ->label() === 'membership is overridden') {

    // Create a membership for the group owner that also has been granted the
    // custom 'moderator' role.
    $membership = Og::createMembership($entity, $entity
      ->getOwner());
    $membership
      ->addRole(OgRole::loadByGroupAndName($entity, 'moderator'));
    $membership
      ->save();
  }
}