You are here

protected function LogPermissions::buildPermissions in Log entity 8

Returns a list of log permissions for a given log type.

Parameters

\Drupal\log\Entity\LogType $type: The log type.

Return value

array An associative array of permission names and descriptions.

1 call to LogPermissions::buildPermissions()
LogPermissions::logTypePermissions in src/LogPermissions.php
Returns an array of log type permissions.

File

src/LogPermissions.php, line 48
Contains \Drupal\log\LogPermissions.

Class

LogPermissions
Provides dynamic permissions for logs of different types.

Namespace

Drupal\log

Code

protected function buildPermissions(LogType $type) {
  $type_id = $type
    ->id();
  $type_params = array(
    '%type_name' => $type
      ->label(),
  );
  $ops = array(
    'view',
    'edit',
    'delete',
  );
  $scopes = array(
    'any',
    'own',
  );
  $permissions = [];
  $permissions["create {$type_id} log entities"] = [
    'title' => $this
      ->t('%type_name: Create new log entities', $type_params),
  ];
  foreach ($ops as $op) {
    foreach ($scopes as $scope) {
      $scope_params = $type_params + [
        '%scope' => $scope,
        '%op' => ucfirst($op),
      ];
      $permissions["{$op} {$scope} {$type_id} log entities"] = [
        'title' => $this
          ->t('%type_name: %op %scope log entities', $scope_params),
      ];
    }
  }
  $permissions["view {$type_id} revisions"] = [
    'title' => $this
      ->t('%type_name: View log revisions', $type_params),
  ];
  $permissions["revert {$type_id} revisions"] = [
    'title' => $this
      ->t('%type_name: Revert log revisions', $type_params),
  ];
  $permissions["delete {$type_id} revisions"] = [
    'title' => $this
      ->t('%type_name: Delete log revisions', $type_params),
  ];
  return $permissions;
}