You are here

public function PermissionManager::getDefaultGroupPermissions in Organic groups 8

Returns permissions that are enabled by default for the given role.

This returns the group level permissions that are populated by default when a new group is created. For example the 'manage members' permission is granted by default to the administrator role, and the 'subscribe' permission to the anonymous role.

New default permissions can be added by creating an event listener for the PermissionEvent. The default permissions that ship with Organic Groups can be found in OgEventSubscriber::provideDefaultOgPermissions().

Parameters

string $group_entity_type_id: The entity type ID of the group for which to return permissions.

string $group_bundle_id: The bundle ID of the group for which to return permissions.

string|null $role_name: Optional default role name to filter the permissions on. If omitted, all permissions will be returned.

Return value

\Drupal\og\GroupPermission[] An array of permissions that are enabled by default for the given role.

Overrides PermissionManagerInterface::getDefaultGroupPermissions

See also

\Drupal\og\Event\PermissionEventInterface

\Drupal\og\EventSubscriber\OgEventSubscriber::provideDefaultOgPermissions()

File

src/PermissionManager.php, line 45

Class

PermissionManager
Manager for OG permissions.

Namespace

Drupal\og

Code

public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_id, $role_name = NULL) {
  $permissions = $this
    ->getDefaultPermissions($group_entity_type_id, $group_bundle_id, [], $role_name);
  $permissions = array_filter($permissions, function (PermissionInterface $permission) use ($role_name) {

    // Only keep group permissions.
    if (!$permission instanceof GroupPermission) {
      return FALSE;
    }

    // Optionally filter on role name.
    $default_roles = $permission
      ->getDefaultRoles();
    return empty($role_name) || !empty($default_roles) && in_array($role_name, $permission
      ->getDefaultRoles());
  });
  return $permissions;
}