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