You are here

class BlockGroups in Block Group 8

Provides block plugin definitions for blockgroup blocks.

Hierarchy

Expanded class hierarchy of BlockGroups

See also

\Drupal\blockgroup\Plugin\Block\BlockGroup.

File

src/Plugin/Derivative/BlockGroups.php, line 15

Namespace

Drupal\blockgroup\Plugin\Derivative
View source
class BlockGroups extends DeriverBase implements ContainerDeriverInterface {

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

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

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    $entity_manager = $container
      ->get('entity_type.manager');
    return new static($entity_manager
      ->getStorage('block_group_content'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $block_groups = $this->blockGroupStorage
      ->loadMultiple();
    foreach ($block_groups as $block_group) {
      $this->derivatives[$block_group
        ->id()] = $base_plugin_definition;
      $this->derivatives[$block_group
        ->id()]['admin_label'] = $block_group
        ->label();
      $this->derivatives[$block_group
        ->id()]['config_dependencies'][$block_group
        ->getConfigDependencyKey()] = [
        $block_group
          ->getConfigDependencyName(),
      ];
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockGroups::$blockGroupStorage protected property The custom block storage.
BlockGroups::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
BlockGroups::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
BlockGroups::__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