You are here

function statistics_node_links_alter in Zircon Profile 8.0

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

Implements hook_node_links_alter().

File

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

Code

function statistics_node_links_alter(array &$node_links, NodeInterface $entity, array &$context) {
  if ($context['view_mode'] != 'rss') {
    $node_links['#cache']['contexts'][] = 'user.permissions';
    if (\Drupal::currentUser()
      ->hasPermission('view post access counter')) {
      $statistics = statistics_get($entity
        ->id());
      if ($statistics) {
        $links['statistics_counter']['title'] = \Drupal::translation()
          ->formatPlural($statistics['totalcount'], '1 view', '@count views');
        $node_links['statistics'] = array(
          '#theme' => 'links__node__statistics',
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
      }
      $node_links['#cache']['max-age'] = \Drupal::config('statistics.settings')
        ->get('display_max_age');
    }
  }
}