You are here

public function BlockService::getDashboardBlocksContents in Opigno dashboard 8

Same name and namespace in other branches
  1. 3.x src/BlockService.php \Drupal\opigno_dashboard\BlockService::getDashboardBlocksContents()

Returns blocks contents.

File

src/BlockService.php, line 99

Class

BlockService
Class BlockService.

Namespace

Drupal\opigno_dashboard

Code

public function getDashboardBlocksContents() {
  $ids = [];
  foreach ($this
    ->getAvailableBlocks() as $block) {
    $ids[] = $block['id'];
  }
  $blocks = [];
  foreach ($ids as $id) {
    $block = Block::load($this
      ->sanitizeId($id));
    if (!$block) {

      // Try to load old version of block.
      $block = Block::load($this
        ->sanitizeIdOld($id));
    }
    if (!empty($block)) {
      $render = \Drupal::entityTypeManager()
        ->getViewBuilder('block')
        ->view($block);
      $blocks[$id] = \Drupal::service('renderer')
        ->renderRoot($render);
    }
  }
  return $blocks;
}