comment_token_info()
Implements hook_token_info().
File
- core/modules/comment/comment.tokens.inc, line 17
- Builds placeholder replacement tokens for comment-related data.
Code
function comment_token_info() { $type = array( 'name' => t('Comments'), 'description' => t('Tokens for comments posted on the site.'), 'needs-data' => 'comment', ); $tokens = []; // Provide a integration for each entity type except comment. foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type_id == 'comment' || !$entity_type->isSubclassOf(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; // @todo Make this work per field. See https://www.drupal.org/node/2031903. $tokens[$token_type]['comment-count'] = [ 'name' => t("Comment count"), 'description' => t("The number of comments posted on an entity."), ]; $tokens[$token_type]['comment-count-new'] = [ 'name' => t("New comment count"), 'description' => t("The number of comments posted on an entity since the reader last viewed it."), ]; } } // Core comment tokens $comment['cid'] = array( 'name' => t("Comment ID"), 'description' => t("The unique ID of the comment."), ); $comment['hostname'] = array( 'name' => t("IP Address"), 'description' => t("The IP address of the computer the comment was posted from."), ); $comment['mail'] = array( 'name' => t("Email address"), 'description' => t("The email address left by the comment author."), ); $comment['homepage'] = array( 'name' => t("Home page"), 'description' => t("The home page URL left by the comment author."), ); $comment['title'] = array( 'name' => t("Title"), 'description' => t("The title of the comment."), ); $comment['body'] = array( 'name' => t("Content"), 'description' => t("The formatted content of the comment itself."), ); $comment['langcode'] = array( 'name' => t('Language code'), 'description' => t('The language code of the language the comment is written in.'), ); $comment['url'] = array( 'name' => t("URL"), 'description' => t("The URL of the comment."), ); $comment['edit-url'] = array( 'name' => t("Edit URL"), 'description' => t("The URL of the comment's edit page."), ); // Chained tokens for comments $comment['created'] = array( 'name' => t("Date created"), 'description' => t("The date the comment was posted."), 'type' => 'date', ); $comment['changed'] = array( 'name' => t("Date changed"), 'description' => t("The date the comment was most recently updated."), 'type' => 'date', ); $comment['parent'] = array( 'name' => t("Parent"), 'description' => t("The comment's parent, if comment threading is active."), 'type' => 'comment', ); $comment['entity'] = array( 'name' => t("Entity"), 'description' => t("The entity the comment was posted to."), 'type' => 'entity', ); $comment['author'] = array( 'name' => t("Author"), 'description' => t("The author name of the comment."), 'type' => 'user', ); return array( 'types' => array('comment' => $type), 'tokens' => array( 'comment' => $comment, ) + $tokens, ); }
Please login to continue.