You are here

public function DefaultRoleEvent::addRole in Organic groups 8

Adds a default role.

Parameters

\Drupal\og\Entity\OgRole $role: The OgRole entity to add. This should be an unsaved entity that doesn't have the group entity type and bundle IDs set.

Throws

\InvalidArgumentException Thrown when the role that is added already exists.

Overrides DefaultRoleEventInterface::addRole

2 calls to DefaultRoleEvent::addRole()
DefaultRoleEvent::addRoles in src/Event/DefaultRoleEvent.php
Adds multiple default roles.
DefaultRoleEvent::setRole in src/Event/DefaultRoleEvent.php
Sets a default roles.

File

src/Event/DefaultRoleEvent.php, line 46

Class

DefaultRoleEvent
Event that is fired when default roles are compiled.

Namespace

Drupal\og\Event

Code

public function addRole(OgRole $role) {
  $this
    ->validate($role);
  if (array_key_exists($role
    ->getName(), $this->roles)) {
    throw new \InvalidArgumentException("The '{$role->getName()}' role already exists.");
  }
  $this->roles[$role
    ->getName()] = $role;
}