class NotePermissions in Drupal PM (Project Management) 4.x
Provides dynamic permissions for Note of different types.
Hierarchy
- class \Drupal\pm_note\NotePermissions uses StringTranslationTrait
Expanded class hierarchy of NotePermissions
File
- modules/
pm_note/ src/ NotePermissions.php, line 13
Namespace
Drupal\pm_noteView source
class NotePermissions {
use StringTranslationTrait;
/**
* Returns an array of node type permissions.
*
* @return array
* The Note by bundle permissions.
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function generatePermissions() {
$perms = [];
foreach (Note::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
/**
* Returns a list of node permissions for a given node type.
*
* @param \Drupal\pm_note\Entity\Note $type
* The Note type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(Note $type) {
$type_id = 'pm_note ' . $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"{$type_id} create entities" => [
'title' => $this
->t('Create new %type_name entities', $type_params),
],
"{$type_id} edit own entities" => [
'title' => $this
->t('Edit own %type_name entities', $type_params),
],
"{$type_id} edit any entities" => [
'title' => $this
->t('Edit any %type_name entities', $type_params),
],
"{$type_id} delete own entities" => [
'title' => $this
->t('Delete own %type_name entities', $type_params),
],
"{$type_id} delete any entities" => [
'title' => $this
->t('Delete any %type_name entities', $type_params),
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NotePermissions:: |
protected | function | Returns a list of node permissions for a given node type. | |
NotePermissions:: |
public | function | Returns an array of node type permissions. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |