OsVersion.php in Dashboards with Layout Builder 8
File
modules/dashboards_matomo/src/Plugin/Dashboard/OsVersion.php
View source
<?php
namespace Drupal\dashboards_matomo\Plugin\Dashboard;
use Drupal\dashboards\Plugin\DashboardBase;
class OsVersion extends MatomoBase {
public static function lazyBuild(DashboardBase $plugin, array $configuration) : array {
try {
$response = $plugin
->query('DevicesDetection.getOsFamilies', [
'filter_limit' => 20,
'period' => $configuration['period'],
'date' => $plugin
->getDateTranslated($configuration['date']),
'flat' => 1,
]);
if (empty($response)) {
$plugin
->setEmpty(TRUE);
return $plugin
->renderChart($configuration);
}
$plugin
->buildDateRows($response, $plugin
->t('Time'), [
'nb_visits',
]);
$plugin
->setChartType($configuration['chart_type']);
return $plugin
->renderChart($configuration);
} catch (\Exception $ex) {
return [
'#markup' => $plugin
->t('Error occured: @error', [
'@error' => $ex
->getMessage(),
]),
'#cache' => [
'max-age' => 0,
],
];
}
}
}