You are here

class BlockContent in Drupal 8

Same name in this branch
  1. 8 core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
  2. 8 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent
  3. 8 core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
Same name and namespace in other branches
  1. 9 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent
  2. 10 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent

Retrieves block plugin definitions for all custom blocks.

Hierarchy

Expanded class hierarchy of BlockContent

File

core/modules/block_content/src/Plugin/Derivative/BlockContent.php, line 13

Namespace

Drupal\block_content\Plugin\Derivative
View source
class BlockContent extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The custom block storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $blockContentStorage;

  /**
   * Constructs a BlockContent object.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
   *   The custom block storage.
   */
  public function __construct(EntityStorageInterface $block_content_storage) {
    $this->blockContentStorage = $block_content_storage;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $block_contents = $this->blockContentStorage
      ->loadByProperties([
      'reusable' => TRUE,
    ]);

    // Reset the discovered definitions.
    $this->derivatives = [];

    /** @var $block_content \Drupal\block_content\Entity\BlockContent */
    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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockContent::$blockContentStorage protected property The custom block storage.
BlockContent::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
BlockContent::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
BlockContent::__construct public function Constructs a BlockContent object.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition