You are here

function statistics_get in Drupal 8

Same name and namespace in other branches
  1. 4 modules/statistics.module \statistics_get()
  2. 5 modules/statistics/statistics.module \statistics_get()
  3. 6 modules/statistics/statistics.module \statistics_get()
  4. 7 modules/statistics/statistics.module \statistics_get()

Retrieves a node's "view statistics".

Deprecated

in drupal:8.2.0 and is removed from drupal:9.0.0. Use \Drupal::service('statistics.storage.node')->fetchView($id) instead.

See also

https://www.drupal.org/node/2778245

1 call to statistics_get()
StatisticsDeprecationsTest::testStatisticsGetDeprecation in core/modules/statistics/tests/src/Kernel/StatisticsDeprecationsTest.php
@expectedDeprecation statistics_get() is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use Drupal::service('statistics.storage.node')->fetchView() instead. See https://www.drupal.org/node/2778245

File

core/modules/statistics/statistics.module, line 131
Logs and displays content statistics for a site.

Code

function statistics_get($id) {
  @trigger_error("statistics_get() is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use Drupal::service('statistics.storage.node')->fetchView() instead. See https://www.drupal.org/node/2778245", E_USER_DEPRECATED);
  if ($id > 0) {

    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = \Drupal::service('statistics.storage.node')
      ->fetchView($id);

    // For backwards compatibility, return FALSE if an invalid node ID was
    // passed in.
    if (!$statistics instanceof StatisticsViewsResult) {
      return FALSE;
    }
    return [
      'totalcount' => $statistics
        ->getTotalCount(),
      'daycount' => $statistics
        ->getDayCount(),
      'timestamp' => $statistics
        ->getTimestamp(),
    ];
  }
}