public function ContentStateStatistic::build in Content Planner 8
Build the block and return a renderable array.
Return value
array The render array for the block.
Overrides DashboardBlockBase::build
File
- modules/
content_kanban/ src/ Plugin/ DashboardBlock/ ContentStateStatistic.php, line 97
Class
- ContentStateStatistic
- Provides a Dashboard block for Content Planner Dashboard.
Namespace
Drupal\content_kanban\Plugin\DashboardBlockCode
public function build() {
// Get config.
$config = $this
->getConfiguration();
// Get Workflow ID from config.
$workflow_id = $this
->getCustomConfigByKey($config, 'workflow_id', '');
// Load workflow.
$workflow = Workflow::load($workflow_id);
// If workflow does not exist.
if (!$workflow) {
$message = t('Content Status Statistic: Workflow with ID @id does not exist. Block will not be shown.', [
'@id' => $workflow_id,
]);
$this
->messenger()
->addError($message);
return [];
}
// Get data.
$data = $this->kanbanStatisticService
->getWorkflowStateContentCounts($workflow);
$build = [
'#theme' => 'content_state_statistic',
'#data' => $data,
'#attached' => [
'library' => [
'content_kanban/content_state_statistic',
],
],
];
return $build;
}