Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
66
web/core/modules/statistics/statistics.tokens.inc
Normal file
66
web/core/modules/statistics/statistics.tokens.inc
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Builds placeholder replacement tokens for node visitor statistics.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
*/
|
||||
function statistics_token_info() {
|
||||
$node['total-count'] = array(
|
||||
'name' => t("Number of views"),
|
||||
'description' => t("The number of visitors who have read the node."),
|
||||
);
|
||||
$node['day-count'] = array(
|
||||
'name' => t("Views today"),
|
||||
'description' => t("The number of visitors who have read the node today."),
|
||||
);
|
||||
$node['last-view'] = array(
|
||||
'name' => t("Last view"),
|
||||
'description' => t("The date on which a visitor last read the node."),
|
||||
'type' => 'date',
|
||||
);
|
||||
|
||||
return array(
|
||||
'tokens' => array('node' => $node),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
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;
|
||||
}
|
Reference in a new issue