function statistics_node_view

Same name in other branches
  1. 7.x modules/statistics/statistics.module \statistics_node_view()
  2. 8.9.x core/modules/statistics/statistics.module \statistics_node_view()
  3. 10 core/modules/statistics/statistics.module \statistics_node_view()
  4. 11.x core/modules/statistics/statistics.module \statistics_node_view()

Implements hook_ENTITY_TYPE_view() for node entities.

File

core/modules/statistics/statistics.module, line 40

Code

function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
    if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
        $build['#attached']['library'][] = 'statistics/drupal.statistics';
        $settings = [
            'data' => [
                'nid' => $node->id(),
            ],
            'url' => \Drupal::request()->getBasePath() . '/' . \Drupal::service('extension.list.module')->getPath('statistics') . '/statistics.php',
        ];
        $build['#attached']['drupalSettings']['statistics'] = $settings;
    }
}

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