class SiteSettingTypePermissions in Site Settings and Labels 8
Provides dynamic permissions for site_setting of different types.
Hierarchy
- class \Drupal\site_settings_type_permissions\SiteSettingTypePermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of SiteSettingTypePermissions
File
- modules/
site_settings_type_permissions/ src/ SiteSettingTypePermissions.php, line 14
Namespace
Drupal\site_settings_type_permissionsView source
class SiteSettingTypePermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* SiteSettingPermissions constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(\Drupal::service('entity_type.manager'));
}
/**
* Returns an array of site_settings type permissions.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* Thrown if the entity type doesn't exist.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* Thrown if the storage handler couldn't be loaded.
*
* @return array
* The site_settings type permissions.
*
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function siteSettingTypePermissionsList() {
$perms = [];
$site_settings_types = $this->entityTypeManager
->getStorage('site_setting_entity_type')
->loadMultiple();
// Generate site_setting permissions for all site_setting types.
foreach ($site_settings_types as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
/**
* Returns a list of site_setting permissions for a given site_setting type.
*
* @param \Drupal\site_settings\Entity\SiteSettingEntityType $type
* The site_settings type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(SiteSettingEntityType $type) {
$type_id = $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"view published {$type_id} site setting entities" => [
'title' => $this
->t('%type_name: View published site settings', $type_params),
],
"view unpublished {$type_id} site setting entities" => [
'title' => $this
->t('%type_name: View unpublished site settings', $type_params),
],
"create {$type_id} site setting" => [
'title' => $this
->t('%type_name: Create new site setting', $type_params),
],
"edit {$type_id} site setting" => [
'title' => $this
->t('%type_name: Edit site setting', $type_params),
],
"delete {$type_id} site setting" => [
'title' => $this
->t('%type_name: Delete site setting', $type_params),
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SiteSettingTypePermissions:: |
protected | property | The entity type manager service. | |
SiteSettingTypePermissions:: |
protected | function | Returns a list of site_setting permissions for a given site_setting type. | |
SiteSettingTypePermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
SiteSettingTypePermissions:: |
public | function | Returns an array of site_settings type permissions. | |
SiteSettingTypePermissions:: |
public | function | SiteSettingPermissions constructor. | |
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. |