BlockManager.php in Drupal 8
File
core/lib/Drupal/Core/Block/BlockManager.php
View source
<?php
namespace Drupal\Core\Block;
use Drupal\Component\Plugin\FallbackPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\FilteredPluginManagerTrait;
use Psr\Log\LoggerInterface;
class BlockManager extends DefaultPluginManager implements BlockManagerInterface, FallbackPluginManagerInterface {
use CategorizingPluginManagerTrait {
getSortedDefinitions as traitGetSortedDefinitions;
}
use FilteredPluginManagerTrait;
protected $logger;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LoggerInterface $logger) {
parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\\Core\\Block\\BlockPluginInterface', 'Drupal\\Core\\Block\\Annotation\\Block');
$this
->alterInfo($this
->getType());
$this
->setCacheBackend($cache_backend, 'block_plugins');
$this->logger = $logger;
}
protected function getType() {
return 'block';
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
$this
->processDefinitionCategory($definition);
}
public function getSortedDefinitions(array $definitions = NULL) {
$definitions = $this
->traitGetSortedDefinitions($definitions, 'admin_label');
unset($definitions['broken']);
return $definitions;
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
protected function handlePluginNotFound($plugin_id, array $configuration) {
$this->logger
->warning('The "%plugin_id" was not found', [
'%plugin_id' => $plugin_id,
]);
return parent::handlePluginNotFound($plugin_id, $configuration);
}
}
Classes
Name |
Description |
BlockManager |
Manages discovery and instantiation of block plugins. |