function statistics_node_view

Same name in other branches
  1. 7.x modules/statistics/statistics.module \statistics_node_view()
  2. 9 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 41

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_get_path('module', '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.