You are here

public function TBMegaMenuBuilder::getAllBlocks in The Better Mega Menu 8

Same name and namespace in other branches
  1. 2.x src/TBMegaMenuBuilder.php \Drupal\tb_megamenu\TBMegaMenuBuilder::getAllBlocks()

Get all of blocks in system without blocks which belong to TB Mega Menu.

In array, each element includes key which is plugin_id and value which is label of block.

@staticvar array $_blocks_array

Return value

\Drupal\Core\Entity\EntityTypeInterface[] An array of block entities or an empty array if none found.

Overrides TBMegaMenuBuilderInterface::getAllBlocks

File

src/TBMegaMenuBuilder.php, line 236

Class

TBMegaMenuBuilder
Defines a TBMegaMenuBuilder.

Namespace

Drupal\tb_megamenu

Code

public function getAllBlocks(string $theme) {
  static $_blocks_array = [];
  if (empty($_blocks_array)) {

    // Get storage handler of block.
    $block_storage = $this->entityTypeManager
      ->getStorage('block');

    // Get the enabled block in the default theme.
    $entity_ids = $block_storage
      ->getQuery()
      ->condition('theme', $theme)
      ->execute();
    $entities = $block_storage
      ->loadMultiple($entity_ids);
    $_blocks_array = [];
    foreach ($entities as $block_id => $block) {
      if ($block
        ->get('settings')['provider'] != 'tb_megamenu') {
        $_blocks_array[$block_id] = $block
          ->label();
      }
    }
    asort($_blocks_array);
  }
  return $_blocks_array;
}