3 namespace Drupal\block_content\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Retrieves block plugin definitions for all custom blocks.
13 class BlockContent extends DeriverBase implements ContainerDeriverInterface {
16 * The custom block storage.
18 * @var \Drupal\Core\Entity\EntityStorageInterface
20 protected $blockContentStorage;
23 * Constructs a BlockContent object.
25 * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
26 * The custom block storage.
28 public function __construct(EntityStorageInterface $block_content_storage) {
29 $this->blockContentStorage = $block_content_storage;
35 public static function create(ContainerInterface $container, $base_plugin_id) {
36 $entity_manager = $container->get('entity.manager');
38 $entity_manager->getStorage('block_content')
45 public function getDerivativeDefinitions($base_plugin_definition) {
46 $block_contents = $this->blockContentStorage->loadByProperties(['reusable' => TRUE]);
47 // Reset the discovered definitions.
48 $this->derivatives = [];
49 /** @var $block_content \Drupal\block_content\Entity\BlockContent */
50 foreach ($block_contents as $block_content) {
51 $this->derivatives[$block_content->uuid()] = $base_plugin_definition;
52 $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
53 $this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = [
54 $block_content->getConfigDependencyName(),
57 return parent::getDerivativeDefinitions($base_plugin_definition);