Commit b3f23196 authored by alexpott's avatar alexpott

Issue #2378565 by aneek, rpayanm, adci_contributor: Add langcode token to comment

parent 04101291
......@@ -53,6 +53,10 @@ function comment_token_info() {
'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."),
......@@ -149,6 +153,10 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements[$original] = $sanitize ? $comment->comment_body->processed : $comment->comment_body->value;
break;
case 'langcode':
$replacements[$original] = $sanitize ? String::checkPlain($comment->language()->getId()) : $comment->language()->getId();
break;
// Comment related URLs.
case 'url':
$url_options['fragment'] = 'comment-' . $comment->id();
......
......@@ -57,6 +57,7 @@ function testCommentTokenReplacement() {
$tests['[comment:homepage]'] = check_url($comment->getHomepage());
$tests['[comment:title]'] = Xss::filter($comment->getSubject());
$tests['[comment:body]'] = $comment->comment_body->processed;
$tests['[comment:langcode]'] = String::checkPlain($comment->language()->getId());
$tests['[comment:url]'] = $comment->url('canonical', $url_options + array('fragment' => 'comment-' . $comment->id()));
$tests['[comment:edit-url]'] = $comment->url('edit-form', $url_options);
$tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->getId());
......@@ -85,6 +86,7 @@ function testCommentTokenReplacement() {
$tests['[comment:homepage]'] = $comment->getHomepage();
$tests['[comment:title]'] = $comment->getSubject();
$tests['[comment:body]'] = $comment->comment_body->value;
$tests['[comment:langcode]'] = $comment->language()->getId();
$tests['[comment:parent:title]'] = $parent_comment->getSubject();
$tests['[comment:entity]'] = $node->getTitle();
$tests['[comment:author:name]'] = $this->adminUser->getUsername();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment