You are here

class SimpleBlock in Simple Block 8

Same name in this branch
  1. 8 src/Entity/SimpleBlock.php \Drupal\simple_block\Entity\SimpleBlock
  2. 8 src/Plugin/Derivative/SimpleBlock.php \Drupal\simple_block\Plugin\Derivative\SimpleBlock

Retrieves block plugin definitions for all custom config blocks.

Hierarchy

Expanded class hierarchy of SimpleBlock

File

src/Plugin/Derivative/SimpleBlock.php, line 13

Namespace

Drupal\simple_block\Plugin\Derivative
View source
class SimpleBlock extends DeriverBase implements ContainerDeriverInterface {

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

  /**
   * Constructs a BlockContent object.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
   *   The custom block storage.
   */
  public function __construct(EntityStorageInterface $block_content_storage) {
    $this->blockConfigStorage = $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('simple_block'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    /** @var \Drupal\simple_block\Entity\SimpleBlock $simple_block */
    foreach ($this->blockConfigStorage
      ->loadMultiple() as $simple_block) {
      $this->derivatives[$simple_block
        ->id()] = $base_plugin_definition;
      $this->derivatives[$simple_block
        ->id()]['admin_label'] = $simple_block
        ->label();
      $this->derivatives[$simple_block
        ->id()]['config_dependencies'][$simple_block
        ->getConfigDependencyKey()] = [
        $simple_block
          ->getConfigDependencyName(),
      ];
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

Members

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