You are here

public function GroupContentPermissionProvider::getPermission in Group 8

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 GroupContentPermissionProviderInterface::getPermission

File

src/Plugin/GroupContentPermissionProvider.php, line 167

Class

GroupContentPermissionProvider
Provides group permissions for GroupContent entities.

Namespace

Drupal\group\Plugin

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;
}