You are here

protected function DashboardController::buildBlocks in Content Planner 8

Build blocks.

Parameters

array $blocks: The blocks to render.

array $plugins: The block plugins.

Return value

array Array of content block render arrays.

1 call to DashboardController::buildBlocks()
DashboardController::showDashboard in src/Controller/DashboardController.php
Showdashboard.

File

src/Controller/DashboardController.php, line 136

Class

DashboardController
Class DashboardController.

Namespace

Drupal\content_planner\Controller

Code

protected function buildBlocks(array &$blocks, array &$plugins) {
  $block_builds = [];

  // Loop over every enabled block.
  foreach ($blocks as $block_id => $block) {

    // If a Dashboard Block plugin exists.
    if (array_key_exists($block_id, $plugins)) {

      /* @var $instance \Drupal\content_planner\DashboardBlockInterface */
      $instance = $this->dashboardBlockPluginManager
        ->createInstance($block_id, $block);
      if (\Drupal::currentUser()
        ->hasPermission('administer content planner dashboard settings')) {
        $has_permission = TRUE;
      }
      else {
        $has_permission = FALSE;
      }

      // Build block render array.
      if ($block_build = $instance
        ->build()) {
        $block_builds[$block_id] = [
          '#theme' => 'content_planner_dashboard_block',
          '#css_id' => str_replace('_', '-', $block_id),
          '#block_id' => $block_id,
          '#name' => isset($block['title']) && $block['title'] ? $block['title'] : $instance
            ->getName(),
          '#has_permission' => $has_permission,
          '#block' => $block_build,
          '#weight' => $block['weight'],
        ];
      }
    }
  }
  return $block_builds;
}