function HistoryTokensHooks::tokens
Implements hook_tokens().
Attributes
#[Hook('tokens')]
File
-
core/
modules/ history/ src/ Hook/ HistoryTokensHooks.php, line 45
Class
- HistoryTokensHooks
- Token hook implementations for history.
Namespace
Drupal\history\HookCode
public function tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) : array {
$replacements = [];
if ($type != 'comment' || empty($data['comment'])) {
if (!empty($data[$type]) && $data[$type] instanceof FieldableEntityInterface) {
$entity = $data[$type];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'comment-count-new':
$replacements[$original] = \Drupal::service(HistoryManager::class)->getCountNewComments($entity);
break;
}
}
}
}
return $replacements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.