You are here

public function PermissionProvider::getPermission in Group 2.0.x

Gets the name of the permission for the given operation, target and scope.

Parameters

string $operation: The permission operation. Usually "create", "view", "update" or "delete".

string $target: The target of the operation. Can be 'relation' or 'entity'.

string $scope: (optional) Whether the 'any' or 'own' permission name should be returned. Defaults to 'any'.

Return value

string|false The permission name or FALSE if it does not apply.

Overrides PermissionProviderTrait::getPermission

1 call to PermissionProvider::getPermission()
PermissionProvider::buildPermissions in src/Plugin/Group/RelationHandlerDefault/PermissionProvider.php
Provides a list of group permissions the plugin exposes.

File

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

Class

PermissionProvider
Provides group permissions for group relation plugins.

Namespace

Drupal\group\Plugin\Group\RelationHandlerDefault

Code

public function getPermission($operation, $target, $scope = 'any') {
  assert(in_array($target, [
    'relation',
    'entity',
  ], TRUE), '$target must be either "relation" or "entity"');
  assert(in_array($scope, [
    'any',
    'own',
  ], TRUE), '$target must be either "relation" or "entity"');
  if ($target === 'relation') {
    switch ($operation) {
      case 'view':
        return $this
          ->getRelationViewPermission($scope);
      case 'update':
        return $this
          ->getRelationUpdatePermission($scope);
      case 'delete':
        return $this
          ->getRelationDeletePermission($scope);
      case 'create':
        return $this
          ->getRelationCreatePermission();
    }
  }
  elseif ($target === 'entity') {
    switch ($operation) {
      case 'view':
        return $this
          ->getEntityViewPermission($scope);
      case 'view unpublished':
        return $this
          ->getEntityViewUnpublishedPermission($scope);
      case 'update':
        return $this
          ->getEntityUpdatePermission($scope);
      case 'delete':
        return $this
          ->getEntityDeletePermission($scope);
      case 'create':
        return $this
          ->getEntityCreatePermission();
    }
  }
  return FALSE;
}