BlockPermissionsPermissions.php in Block permissions 8
File
src/BlockPermissionsPermissions.php
View source
<?php
namespace Drupal\block_permissions;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Block\BlockManagerInterface;
class BlockPermissionsPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $blockManager;
protected $themeHandler;
public function __construct(BlockManagerInterface $block_manager, ThemeHandlerInterface $theme_handler) {
$this->blockManager = $block_manager;
$this->themeHandler = $theme_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.block'), $container
->get('theme_handler'));
}
public function permissions() {
$permissions = [];
$themes = $this->themeHandler
->listInfo();
foreach ($themes as $key => $theme) {
if ($theme->status == 1 && (!isset($theme->info['hidden']) || $theme->info['hidden'] != 1)) {
$permissions['administer block settings for theme ' . $key] = [
'title' => $this
->t('Administer block settings for the theme @label', [
'@label' => ucfirst($theme
->getName()),
]),
'description' => $this
->t('This permission refines the administer blocks permission.'),
];
}
}
$definitions = $this->blockManager
->getDefinitions();
$providers = [];
foreach ($definitions as $definition) {
$providers[$definition['provider']] = $definition['provider'];
}
foreach ($providers as $provider) {
$permissions['administer blocks provided by ' . $provider] = [
'title' => $this
->t('Manage blocks provided by @label', [
'@label' => $provider,
]),
'description' => $this
->t('When not given, the user cannot manage blocks provided by this provider.'),
];
}
return $permissions;
}
}