function statistics_get

Same name in other branches
  1. 7.x 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

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(),
        ];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.