You are here

public function PermissionProvider::buildPermissions in Group 2.0.x

Provides a list of group permissions the plugin exposes.

If you have some group permissions that would only make sense when your plugin is installed, you may define those here. They will not be shown on the permission configuration form unless the plugin is installed.

Return value

array An array of group permissions, see GroupPermissionHandlerInterface for the structure of a group permission.

Overrides PermissionProviderTrait::buildPermissions

See also

GroupPermissionHandlerInterface::getPermissions()

File

src/Plugin/Group/RelationHandlerDefault/PermissionProvider.php, line 73

Class

PermissionProvider
Provides group permissions for group relation plugins.

Namespace

Drupal\group\Plugin\Group\RelationHandlerDefault

Code

public function buildPermissions() {
  $permissions = [];

  // Provide permissions for the relation (i.e.: The group content entity).
  $prefix = 'Relation:';
  if ($name = $this
    ->getAdminPermission()) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Administer relations");
    $permissions[$name]['restrict access'] = TRUE;
  }
  if ($name = $this
    ->getPermission('view', 'relation')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View any entity relations");
  }
  if ($name = $this
    ->getPermission('view', 'relation', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View own entity relations");
  }
  if ($name = $this
    ->getPermission('update', 'relation')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Edit any entity relations");
  }
  if ($name = $this
    ->getPermission('update', 'relation', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Edit own entity relations");
  }
  if ($name = $this
    ->getPermission('delete', 'relation')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Delete any entity relations");
  }
  if ($name = $this
    ->getPermission('delete', 'relation', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Delete own entity relations");
  }
  if ($name = $this
    ->getPermission('create', 'relation')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Add entity relations", 'Allows you to add an existing %entity_type entity to the group.');
  }

  // Provide permissions for the actual entity being added to the group.
  $prefix = 'Entity:';
  if ($name = $this
    ->getPermission('view', 'entity')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View any %entity_type entities");
  }
  if ($name = $this
    ->getPermission('view', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View own %entity_type entities");
  }
  if ($name = $this
    ->getPermission('view unpublished', 'entity')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View any unpublished %entity_type entities");
  }
  if ($name = $this
    ->getPermission('view unpublished', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} View own unpublished %entity_type entities");
  }
  if ($name = $this
    ->getPermission('update', 'entity')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Edit any %entity_type entities");
  }
  if ($name = $this
    ->getPermission('update', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Edit own %entity_type entities");
  }
  if ($name = $this
    ->getPermission('delete', 'entity')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Delete any %entity_type entities");
  }
  if ($name = $this
    ->getPermission('delete', 'entity', 'own')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Delete own %entity_type entities");
  }
  if ($name = $this
    ->getPermission('create', 'entity')) {
    $permissions[$name] = $this
      ->buildPermission("{$prefix} Add %entity_type entities", 'Allows you to create a new %entity_type entity and add it to the group.');
  }
  return $permissions;
}