annotate core/lib/Drupal/Core/Block/BlockManager.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
rev   line source
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\Context\ContextAwarePluginManagerTrait;
Chris@0 10 use Drupal\Core\Plugin\DefaultPluginManager;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Manages discovery and instantiation of block plugins.
Chris@0 14 *
Chris@0 15 * @todo Add documentation to this class.
Chris@0 16 *
Chris@0 17 * @see \Drupal\Core\Block\BlockPluginInterface
Chris@0 18 */
Chris@0 19 class BlockManager extends DefaultPluginManager implements BlockManagerInterface, FallbackPluginManagerInterface {
Chris@0 20
Chris@0 21 use CategorizingPluginManagerTrait {
Chris@0 22 getSortedDefinitions as traitGetSortedDefinitions;
Chris@0 23 }
Chris@0 24 use ContextAwarePluginManagerTrait;
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Constructs a new \Drupal\Core\Block\BlockManager object.
Chris@0 28 *
Chris@0 29 * @param \Traversable $namespaces
Chris@0 30 * An object that implements \Traversable which contains the root paths
Chris@0 31 * keyed by the corresponding namespace to look for plugin implementations.
Chris@0 32 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
Chris@0 33 * Cache backend instance to use.
Chris@0 34 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
Chris@0 35 * The module handler to invoke the alter hook with.
Chris@0 36 */
Chris@0 37 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
Chris@0 38 parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\Core\Block\BlockPluginInterface', 'Drupal\Core\Block\Annotation\Block');
Chris@0 39
Chris@0 40 $this->alterInfo('block');
Chris@0 41 $this->setCacheBackend($cache_backend, 'block_plugins');
Chris@0 42 }
Chris@0 43
Chris@0 44 /**
Chris@0 45 * {@inheritdoc}
Chris@0 46 */
Chris@0 47 public function processDefinition(&$definition, $plugin_id) {
Chris@0 48 parent::processDefinition($definition, $plugin_id);
Chris@0 49 $this->processDefinitionCategory($definition);
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * {@inheritdoc}
Chris@0 54 */
Chris@0 55 public function getSortedDefinitions(array $definitions = NULL) {
Chris@0 56 // Sort the plugins first by category, then by admin label.
Chris@0 57 $definitions = $this->traitGetSortedDefinitions($definitions, 'admin_label');
Chris@0 58 // Do not display the 'broken' plugin in the UI.
Chris@0 59 unset($definitions['broken']);
Chris@0 60 return $definitions;
Chris@0 61 }
Chris@0 62
Chris@0 63 /**
Chris@0 64 * {@inheritdoc}
Chris@0 65 */
Chris@0 66 public function getFallbackPluginId($plugin_id, array $configuration = []) {
Chris@0 67 return 'broken';
Chris@0 68 }
Chris@0 69
Chris@0 70 }