Country.php in Dashboards with Layout Builder 8
File
modules/dashboards_matomo/src/Plugin/Dashboard/Country.php
View source
<?php
namespace Drupal\dashboards_matomo\Plugin\Dashboard;
use Drupal\dashboards\Plugin\DashboardBase;
class Country extends MatomoBase {
public static function lazyBuild(DashboardBase $plugin, array $configuration) : array {
try {
$response = $plugin
->query('UserCountry.getCountry', [
'filter_limit' => 30,
'period' => $configuration['period'],
'date' => $plugin
->getDateTranslated($configuration['date']),
'flat' => 1,
]);
$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,
],
];
}
}
}