You are here

private function Blocks::listBlocks in DRD Agent 8.3

Same name and namespace in other branches
  1. 4.0.x src/Agent/Action/Blocks.php \Drupal\drd_agent\Agent\Action\Blocks::listBlocks()

Collect all available blocks and return them as a list.

Return value

array List of block indexed by provider and ID, showing their label as value.

1 call to Blocks::listBlocks()
Blocks::execute in src/Agent/Action/Blocks.php
Execute an action.

File

src/Agent/Action/Blocks.php, line 20

Class

Blocks
Provides a 'Blocks' code.

Namespace

Drupal\drd_agent\Agent\Action

Code

private function listBlocks() : array {
  $block_list = [];
  try {
    $blb = BlockListBuilder::createInstance($this->container, $this->entityTypeManager
      ->getDefinition('block'));

    /** @var \Drupal\block\BlockInterface[] $blocks */
    $blocks = $blb
      ->load();
    foreach ($blocks as $id => $block) {
      $definition = $block
        ->getPlugin()
        ->getPluginDefinition();
      $block_list[$definition['provider']][$id] = $block
        ->label();
    }
  } catch (PluginNotFoundException $e) {

    // Ignore.
  }
  return $block_list;
}