You are here

public function DashboardController::showDashboard in Content Planner 8

Showdashboard.

Return value

array The content planner dashboard render array.

1 string reference to 'DashboardController::showDashboard'
content_planner.routing.yml in ./content_planner.routing.yml
content_planner.routing.yml

File

src/Controller/DashboardController.php, line 89

Class

DashboardController
Class DashboardController.

Namespace

Drupal\content_planner\Controller

Code

public function showDashboard() {

  // Check if Content Calendar or Kanban is enabled.
  if (!$this->dashboardService
    ->isContentCalendarEnabled() && !$this->dashboardService
    ->isContentKanbanEnabled()) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('This dashboard can only be used with Content Calendar or Content Kanban enabled'), 'error');
    return [];
  }

  // Get enabled blocks.
  $blocks = $this->dashboardSettingsService
    ->getBlockConfigurations();

  // If there are no blocks enabled, display error message.
  if (!$blocks) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Dashboard is not configured yet. Please do this in the Settings tab.'), 'error');
    return [];
  }

  // Get registered Plugins.
  $plugins = $this->dashboardBlockPluginManager
    ->getDefinitions();

  // Build blocks.
  $block_builds = $this
    ->buildBlocks($blocks, $plugins);
  $build = [
    '#theme' => 'content_planner_dashboard',
    '#blocks' => $block_builds,
    '#attached' => [
      'library' => [
        'content_planner/dashboard',
      ],
    ],
  ];
  return $build;
}