function HistoryTokensHooks::tokenInfo

Implements hook_token_info().

Attributes

#[Hook('token_info')]

File

core/modules/history/src/Hook/HistoryTokensHooks.php, line 22

Class

HistoryTokensHooks
Token hook implementations for history.

Namespace

Drupal\history\Hook

Code

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,
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.