SiteSettingTypePermissions.php in Site Settings and Labels 8
File
modules/site_settings_type_permissions/src/SiteSettingTypePermissions.php
View source
<?php
namespace Drupal\site_settings_type_permissions;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\site_settings\Entity\SiteSettingEntityType;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SiteSettingTypePermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static(\Drupal::service('entity_type.manager'));
}
public function siteSettingTypePermissionsList() {
$perms = [];
$site_settings_types = $this->entityTypeManager
->getStorage('site_setting_entity_type')
->loadMultiple();
foreach ($site_settings_types as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
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),
],
];
}
}