class Permissions in Block Access 8
Defines a class for generating block content permissions per type.
Hierarchy
- class \Drupal\block_access\Permissions uses StringTranslationTrait
Expanded class hierarchy of Permissions
File
- src/
Permissions.php, line 12
Namespace
Drupal\block_accessView source
class Permissions {
use StringTranslationTrait;
/**
* Gets permissions.
*
* @return array
* Array of permissions as per permissions.yml format.
*/
public function get() {
$permissions = [];
// Generate permissions for all block types types.
foreach (BlockContentType::loadMultiple() as $type) {
$permissions += $this
->buildPermissions($type);
}
return $permissions;
}
/**
* Returns a list of block content permissions for a given type.
*
* @param \Drupal\block_content\BlockContentTypeInterface $type
* The block content type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(BlockContentTypeInterface $type) {
$type_id = $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"create {$type_id} block_content" => [
'title' => $this
->t('%type_name: Create new block content', $type_params),
],
"update own {$type_id} block_content" => [
'title' => $this
->t('%type_name: Edit own block content', $type_params),
],
"update any {$type_id} block_content" => [
'title' => $this
->t('%type_name: Edit any block content', $type_params),
],
"delete own {$type_id} block_content" => [
'title' => $this
->t('%type_name: Delete own block content', $type_params),
],
"delete any {$type_id} block_content" => [
'title' => $this
->t('%type_name: Delete any block content', $type_params),
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Permissions:: |
protected | function | Returns a list of block content permissions for a given type. | |
Permissions:: |
public | function | Gets 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. |