public function OgRoleManager::createPerBundleRoles in Organic groups 8
Creates the roles for the given group type, based on the default roles.
This is intended to be called after a new group type has been created.
Parameters
string $entity_type_id: The entity type ID of the group for which to create default roles.
string $bundle_id: The bundle ID of the group for which to create default roles.
Return value
\Drupal\og\Entity\OgRole[] Array with the saved OG roles that were created
Overrides OgRoleManagerInterface::createPerBundleRoles
File
- src/
OgRoleManager.php, line 64
Class
- OgRoleManager
- Defines a manager of an OG role.
Namespace
Drupal\ogCode
public function createPerBundleRoles($entity_type_id, $bundle_id) {
$roles = [];
foreach ($this
->getDefaultRoles() as $role) {
$role
->setGroupType($entity_type_id);
$role
->setGroupBundle($bundle_id);
// Populate the default roles with a set of default permissions.
$permissions = $this->permissionManager
->getDefaultGroupPermissions($entity_type_id, $bundle_id, $role
->getName());
foreach (array_keys($permissions) as $permission) {
$role
->grantPermission($permission);
}
$role
->save();
$roles[] = $role;
}
return $roles;
}