You are here

function statistics_node_view in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/statistics/statistics.module \statistics_node_view()
  2. 7 modules/statistics/statistics.module \statistics_node_view()

Implements hook_ENTITY_TYPE_view() for node entities.

File

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

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;
  }
}