DefaultController.php in Block Blacklist [Deprecated] 8
File
src/Controller/DefaultController.php
View source
<?php
namespace Drupal\block_blacklist\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Plugin\Context\LazyContextRepository;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\block_blacklist\Blacklist;
class DefaultController extends ControllerBase {
protected $blockManager;
protected $contextRepository;
protected $configFactory;
protected $blacklistService;
public function __construct(BlockManagerInterface $block_manager, LazyContextRepository $context_repository, ConfigFactoryInterface $config_factory, Blacklist $blacklist_service) {
$this->blockManager = $block_manager;
$this->contextRepository = $context_repository;
$this->configFactory = $config_factory;
$this->blacklistService = $blacklist_service;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.block'), $container
->get('context.repository'), $container
->get('config.factory'), $container
->get('block_blacklist.blacklist'));
}
public function list() {
$definitions = $this
->getList();
$header = [
$this
->t('Module'),
$this
->t('Label'),
$this
->t('Block ID'),
];
$rows = [];
foreach ($definitions as $id => $definition) {
$rows[] = [
$definition['provider'],
$definition['admin_label'],
$id,
];
}
return [
'#type' => 'table',
'#caption' => $this
->getCaption(),
'#header' => $header,
'#rows' => $rows,
];
}
protected function getCaption() {
return $this
->t('This page lists all system-wide block IDs for all contexts.');
}
protected function getList() {
$contexts = $this->contextRepository
->getAvailableContexts();
return $this->blockManager
->getDefinitionsForContexts($contexts);
}
}