View source
<?php
declare (strict_types=1);
namespace Drupal\theme_permission;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
class ThemePerm implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $themeHandler;
public function __construct(ThemeHandlerInterface $theme_handler) {
$this->themeHandler = $theme_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('theme_handler'));
}
public function dynamicPermissions() {
$perms = [];
$themes = $this->themeHandler
->listInfo();
foreach ($themes as $theme => $value) {
$type_params = [
'%themename' => $theme,
];
$perms += [
"administer themes {$theme}" => [
'title' => $this
->t('administer themes %themename', $type_params),
],
"uninstall themes {$theme}" => [
'title' => $this
->t('uninstall themes %themename', $type_params),
],
"Edit Administration theme" => [
'title' => $this
->t('Edit Administration theme'),
],
];
}
return $perms;
}
}