You are here

public static function Browser::lazyBuild in Dashboards with Layout Builder 2.0.x

Same name and namespace in other branches
  1. 8 modules/dashboards_matomo/src/Plugin/Dashboard/Browser.php \Drupal\dashboards_matomo\Plugin\Dashboard\Browser::lazyBuild()

Lazy build callback.

Parameters

\Drupal\dashboards\Plugin\DashboardBase $plugin: Matomo base plugin.

array $configuration: Configuration.

Overrides DashboardLazyBuildInterface::lazyBuild

File

modules/dashboards_matomo/src/Plugin/Dashboard/Browser.php, line 26

Class

Browser
Show account info.

Namespace

Drupal\dashboards_matomo\Plugin\Dashboard

Code

public static function lazyBuild(DashboardBase $plugin, array $configuration) : array {
  try {
    $response = $plugin
      ->query('DevicesDetection.getBrowsers', [
      '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('Date'), [
      '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,
      ],
    ];
  }
}