BlockContent.php in Drupal 10
File
core/modules/block_content/src/Plugin/Derivative/BlockContent.php
View source
<?php
namespace Drupal\block_content\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BlockContent extends DeriverBase implements ContainerDeriverInterface {
protected $blockContentStorage;
public function __construct(EntityStorageInterface $block_content_storage) {
$this->blockContentStorage = $block_content_storage;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
$entity_type_manager = $container
->get('entity_type.manager');
return new static($entity_type_manager
->getStorage('block_content'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$block_contents = $this->blockContentStorage
->loadByProperties([
'reusable' => TRUE,
]);
$this->derivatives = [];
foreach ($block_contents as $block_content) {
$this->derivatives[$block_content
->uuid()] = $base_plugin_definition;
$this->derivatives[$block_content
->uuid()]['admin_label'] = $block_content
->label();
$this->derivatives[$block_content
->uuid()]['config_dependencies']['content'] = [
$block_content
->getConfigDependencyName(),
];
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Classes
Name |
Description |
BlockContent |
Retrieves block plugin definitions for all custom blocks. |