function statistics_node_view

Implements hook_node_view().

File

drupal/core/modules/statistics/statistics.module, line 104
Logs and displays access statistics for a site.

Code

function statistics_node_view(Node $node, $view_mode) {
  if (!empty($node->nid) && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
    $node->content['#attached']['library'][] = array(
      'statistics',
      'drupal.statistics',
    );
    $settings = array(
      'data' => array(
        'nid' => $node->nid,
      ),
      'url' => url(drupal_get_path('module', 'statistics') . '/statistics.php'),
    );
    $node->content['#attached']['js'][] = array(
      'data' => array(
        'statistics' => $settings,
      ),
      'type' => 'setting',
    );
  }
  if ($view_mode != 'rss') {
    if (user_access('view post access counter')) {
      $statistics = statistics_get($node->nid);
      if ($statistics) {
        $links['statistics_counter']['title'] = format_plural($statistics['totalcount'], '1 view', '@count views');
        $node->content['links']['statistics'] = array(
          '#theme' => 'links__node__statistics',
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
      }
    }
  }
}