class HistoryTokensHooks
Token hook implementations for history.
Hierarchy
- class \Drupal\history\Hook\HistoryTokensHooks uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of HistoryTokensHooks
File
-
core/
modules/ history/ src/ Hook/ HistoryTokensHooks.php, line 15
Namespace
Drupal\history\HookView source
class HistoryTokensHooks {
use StringTranslationTrait;
/**
* Implements hook_token_info().
*/
public function tokenInfo() : array {
$tokens = [];
// Provides an integration for each entity type except comment.
foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type_id == 'comment' || !$entity_type->entityClassImplements(ContentEntityInterface::class)) {
continue;
}
if (\Drupal::service('comment.manager')->getFields($entity_type_id)) {
// Get the correct token type.
$token_type = $entity_type_id == 'taxonomy_term' ? 'term' : $entity_type_id;
$tokens[$token_type]['comment-count-new'] = [
'name' => $this->t("New comment count"),
'description' => $this->t("The number of comments posted on an entity since the reader last viewed it."),
];
}
}
return [
'tokens' => $tokens,
];
}
/**
* Implements hook_tokens().
*/
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;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| HistoryTokensHooks::tokenInfo | public | function | Implements hook_token_info(). | |
| HistoryTokensHooks::tokens | public | function | Implements hook_tokens(). | |
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.