function statistics_tokens
statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata$bubbleable_metadata)
Implements hook_tokens().
File
- core/modules/statistics/statistics.tokens.inc, line 36
- Builds placeholder replacement tokens for node visitor statistics.
Code
function statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $token_service = \Drupal::token(); $replacements = array(); if ($type == 'node' & !empty($data['node'])) { $node = $data['node']; foreach ($tokens as $name => $original) { if ($name == 'total-count') { $statistics = statistics_get($node->id()); $replacements[$original] = $statistics['totalcount']; } elseif ($name == 'day-count') { $statistics = statistics_get($node->id()); $replacements[$original] = $statistics['daycount']; } elseif ($name == 'last-view') { $statistics = statistics_get($node->id()); $replacements[$original] = format_date($statistics['timestamp']); } } if ($created_tokens = $token_service->findWithPrefix($tokens, 'last-view')) { $statistics = statistics_get($node->id()); $replacements += $token_service->generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options, $bubbleable_metadata); } } return $replacements; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!statistics!statistics.tokens.inc/function/statistics_tokens/8.1.x