public function NodeStatistics::buildRenderArray in Dashboards with Layout Builder 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Dashboard/NodeStatistics.php \Drupal\dashboards\Plugin\Dashboard\NodeStatistics::buildRenderArray()
Build render array.
Parameters
array $configuration: Plugin configuration.
Return value
array Return render array.
Overrides DashboardBase::buildRenderArray
File
- src/
Plugin/ Dashboard/ NodeStatistics.php, line 77
Class
- NodeStatistics
- Show account info.
Namespace
Drupal\dashboards\Plugin\DashboardCode
public function buildRenderArray($configuration) : array {
if (isset($configuration['chart_type'])) {
$this
->setChartType($configuration['chart_type']);
}
$types = $this->entityTypeInfo
->getBundleInfo('node');
$rows = [];
$empty = TRUE;
foreach ($types as $bundle => $type) {
$data = $this->entityQuery
->condition('type', $bundle)
->count()
->execute();
$rows[] = [
$type['label'],
$data,
];
if ($data > 0) {
$empty = FALSE;
}
}
if ($empty) {
$rows = [];
$this
->setEmpty(TRUE);
}
$this
->setLabels([
$this
->t('Node Type'),
$this
->t('Count'),
]);
$this
->setRows($rows);
return $this
->renderChart($configuration);
}