You are here

class LogPermissions in Log entity 8

Provides dynamic permissions for logs of different types.

Hierarchy

Expanded class hierarchy of LogPermissions

File

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

Namespace

Drupal\log
View source
class LogPermissions {
  use StringTranslationTrait;
  use UrlGeneratorTrait;

  /**
   * Returns an array of log type permissions.
   *
   * @return array
   *   The log type permissions.
   *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function logTypePermissions() {
    $perms = array();

    // Generate log permissions for all log types.
    foreach (LogType::loadMultiple() as $type) {
      $perms += $this
        ->buildPermissions($type);
    }
    return $perms;
  }

  /**
   * Returns a list of log permissions for a given log type.
   *
   * @param \Drupal\log\Entity\LogType $type
   *   The log type.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LogPermissions::buildPermissions protected function Returns a list of log permissions for a given log type.
LogPermissions::logTypePermissions public function Returns an array of log type permissions.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::redirect Deprecated protected function Returns a redirect response object for the specified route. 3
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.