Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Block;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Plugin\FallbackPluginManagerInterface;
|
Chris@0
|
6 use Drupal\Core\Cache\CacheBackendInterface;
|
Chris@0
|
7 use Drupal\Core\Extension\ModuleHandlerInterface;
|
Chris@0
|
8 use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
|
Chris@0
|
9 use Drupal\Core\Plugin\DefaultPluginManager;
|
Chris@17
|
10 use Drupal\Core\Plugin\FilteredPluginManagerTrait;
|
Chris@17
|
11 use Psr\Log\LoggerInterface;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Manages discovery and instantiation of block plugins.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @todo Add documentation to this class.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @see \Drupal\Core\Block\BlockPluginInterface
|
Chris@0
|
19 */
|
Chris@0
|
20 class BlockManager extends DefaultPluginManager implements BlockManagerInterface, FallbackPluginManagerInterface {
|
Chris@0
|
21
|
Chris@0
|
22 use CategorizingPluginManagerTrait {
|
Chris@0
|
23 getSortedDefinitions as traitGetSortedDefinitions;
|
Chris@0
|
24 }
|
Chris@17
|
25 use FilteredPluginManagerTrait;
|
Chris@17
|
26
|
Chris@17
|
27 /**
|
Chris@17
|
28 * The logger.
|
Chris@17
|
29 *
|
Chris@17
|
30 * @var \Psr\Log\LoggerInterface
|
Chris@17
|
31 */
|
Chris@17
|
32 protected $logger;
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Constructs a new \Drupal\Core\Block\BlockManager object.
|
Chris@0
|
36 *
|
Chris@0
|
37 * @param \Traversable $namespaces
|
Chris@0
|
38 * An object that implements \Traversable which contains the root paths
|
Chris@0
|
39 * keyed by the corresponding namespace to look for plugin implementations.
|
Chris@0
|
40 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
Chris@0
|
41 * Cache backend instance to use.
|
Chris@0
|
42 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
Chris@0
|
43 * The module handler to invoke the alter hook with.
|
Chris@17
|
44 * @param \Psr\Log\LoggerInterface $logger
|
Chris@17
|
45 * The logger.
|
Chris@0
|
46 */
|
Chris@17
|
47 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LoggerInterface $logger) {
|
Chris@0
|
48 parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\Core\Block\BlockPluginInterface', 'Drupal\Core\Block\Annotation\Block');
|
Chris@0
|
49
|
Chris@17
|
50 $this->alterInfo($this->getType());
|
Chris@0
|
51 $this->setCacheBackend($cache_backend, 'block_plugins');
|
Chris@17
|
52 $this->logger = $logger;
|
Chris@17
|
53 }
|
Chris@17
|
54
|
Chris@17
|
55 /**
|
Chris@17
|
56 * {@inheritdoc}
|
Chris@17
|
57 */
|
Chris@17
|
58 protected function getType() {
|
Chris@17
|
59 return 'block';
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * {@inheritdoc}
|
Chris@0
|
64 */
|
Chris@0
|
65 public function processDefinition(&$definition, $plugin_id) {
|
Chris@0
|
66 parent::processDefinition($definition, $plugin_id);
|
Chris@0
|
67 $this->processDefinitionCategory($definition);
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * {@inheritdoc}
|
Chris@0
|
72 */
|
Chris@0
|
73 public function getSortedDefinitions(array $definitions = NULL) {
|
Chris@0
|
74 // Sort the plugins first by category, then by admin label.
|
Chris@0
|
75 $definitions = $this->traitGetSortedDefinitions($definitions, 'admin_label');
|
Chris@0
|
76 // Do not display the 'broken' plugin in the UI.
|
Chris@0
|
77 unset($definitions['broken']);
|
Chris@0
|
78 return $definitions;
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 /**
|
Chris@0
|
82 * {@inheritdoc}
|
Chris@0
|
83 */
|
Chris@0
|
84 public function getFallbackPluginId($plugin_id, array $configuration = []) {
|
Chris@0
|
85 return 'broken';
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@17
|
88 /**
|
Chris@17
|
89 * {@inheritdoc}
|
Chris@17
|
90 */
|
Chris@17
|
91 protected function handlePluginNotFound($plugin_id, array $configuration) {
|
Chris@17
|
92 $this->logger->warning('The "%plugin_id" was not found', ['%plugin_id' => $plugin_id]);
|
Chris@17
|
93 return parent::handlePluginNotFound($plugin_id, $configuration);
|
Chris@17
|
94 }
|
Chris@17
|
95
|
Chris@0
|
96 }
|