public static function Country::lazyBuild in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x modules/dashboards_matomo/src/Plugin/Dashboard/Country.php \Drupal\dashboards_matomo\Plugin\Dashboard\Country::lazyBuild()
Lazy build callback.
Parameters
\Drupal\dashboards\Plugin\MatomoBase $plugin: Matomo base plugin.
array $configuration: Configuration.
Overrides DashboardLazyBuildInterface::lazyBuild
File
- modules/dashboards_matomo/ src/ Plugin/ Dashboard/ Country.php, line 26 
Class
- Country
- Show account info.
Namespace
Drupal\dashboards_matomo\Plugin\DashboardCode
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,
      ],
    ];
  }
}