You are here

public function BlockService::getDashboardBlocksContents in Opigno dashboard 3.x

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

Returns blocks contents.

Return value

array The list of dashboard blocks to be rendered.

Overrides BlockServiceInterface::getDashboardBlocksContents

File

src/BlockService.php, line 173

Class

BlockService
The dashboard block manager service definition.

Namespace

Drupal\opigno_dashboard

Code

public function getDashboardBlocksContents() : array {
  $ids = [];
  foreach ($this
    ->getAvailableBlocks() as $block) {
    $ids[] = $block['id'];
  }
  $data = [
    'attachments' => [],
  ];
  foreach ($ids as $id) {
    try {
      $block = $this->blockManager
        ->createInstance($id);
    } catch (PluginException $e) {
      watchdog_exception('opigno_dashboard_exception', $e);
      continue;
    }
    if (!$block instanceof BlockBase) {
      continue;
    }
    $render = $block
      ->build();
    $data['blocks'][$id] = $this->renderer
      ->renderRoot($render);
    $attachments = $render['#attached'] ?? [];
    $data['attachments'] = array_merge_recursive($data['attachments'], $attachments);
  }
  return $data;
}