public function MostReaded::buildRenderArray in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x modules/dashboards_statistic/src/Plugin/Dashboard/MostReaded.php \Drupal\dashboards_statistic\Plugin\Dashboard\MostReaded::buildRenderArray()
Build render array.
Parameters
array $configuration: Plugin configuration.
Return value
array Return render array.
Overrides DashboardBase::buildRenderArray
File
- modules/
dashboards_statistic/ src/ Plugin/ Dashboard/ MostReaded.php, line 90
Class
- MostReaded
- Show account info.
Namespace
Drupal\dashboards_statistic\Plugin\DashboardCode
public function buildRenderArray($configuration) : array {
$stats = [];
$field = 'totalcount';
if ($configuration['count'] == 'daycount') {
$field = 'daycount';
}
$cache = $this
->getCache($field);
if (!$cache) {
$query = $this->database
->select('node_field_data', 'nfd');
$query
->join('node_counter', 'nc', 'nc.nid = nfd.nid');
$query
->fields('nfd', [
'type',
]);
$query
->addExpression('SUM(nc.' . $field . ')', 'count');
$query
->groupBy('type');
$rows = [];
$stats['types'] = $query
->execute()
->fetchAllAssoc('type');
foreach ($stats['types'] as $type => $count) {
$rows[] = [
$type,
$count->count,
];
}
$this
->setCache($field, $rows, CacheBackendInterface::CACHE_PERMANENT, [
'node_list',
]);
}
else {
$rows = $cache->data;
}
$this
->setLabels([
$this
->t('Node Type'),
$this
->t('Count'),
]);
$this
->setRows($rows);
$build = $this
->renderChart($configuration);
$build['#cache'] = [
'tags' => [
'node_list',
],
];
return $build;
}