3 namespace Drupal\block;
5 use Drupal\Component\Plugin\Exception\PluginException;
6 use Drupal\Component\Plugin\PluginManagerInterface;
7 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
10 * Provides a collection of block plugins.
12 class BlockPluginCollection extends DefaultSingleLazyPluginCollection {
15 * The block ID this plugin collection belongs to.
22 * Constructs a new BlockPluginCollection.
24 * @param \Drupal\Component\Plugin\PluginManagerInterface $manager
25 * The manager to be used for instantiating plugins.
26 * @param string $instance_id
27 * The ID of the plugin instance.
28 * @param array $configuration
29 * An array of configuration.
30 * @param string $block_id
31 * The unique ID of the block entity using this plugin.
33 public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration, $block_id) {
34 parent::__construct($manager, $instance_id, $configuration);
36 $this->blockId = $block_id;
42 * @return \Drupal\Core\Block\BlockPluginInterface
44 public function &get($instance_id) {
45 return parent::get($instance_id);
51 protected function initializePlugin($instance_id) {
53 throw new PluginException("The block '{$this->blockId}' did not specify a plugin.");
57 parent::initializePlugin($instance_id);
59 catch (PluginException $e) {
60 $module = $this->configuration['provider'];
61 // Ignore blocks belonging to uninstalled modules, but re-throw valid
62 // exceptions when the module is installed and the plugin is
64 if (!$module || \Drupal::moduleHandler()->moduleExists($module)) {