class LogPermissions in Log entity 8
Provides dynamic permissions for logs of different types.
Hierarchy
- class \Drupal\log\LogPermissions uses UrlGeneratorTrait, StringTranslationTrait
Expanded class hierarchy of LogPermissions
File
- src/
LogPermissions.php, line 17 - Contains \Drupal\log\LogPermissions.
Namespace
Drupal\logView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LogPermissions:: |
protected | function | Returns a list of log permissions for a given log type. | |
LogPermissions:: |
public | function | Returns an array of log type permissions. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | 3 |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |