diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 789ede30d039029f5bea305e0cb7071283ba01ab..8f6d008363555bfed75b2404a9d75de6a2c4f45d 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -37,10 +37,6 @@ function comment_token_info() { 'name' => t("IP Address"), 'description' => t("The IP address of the computer the comment was posted from."), ); - $comment['name'] = array( - 'name' => t("Name"), - 'description' => t("The name left by the comment author."), - ); $comment['mail'] = array( 'name' => t("Email address"), 'description' => t("The email address left by the comment author."), @@ -96,7 +92,7 @@ function comment_token_info() { ); $comment['author'] = array( 'name' => t("Author"), - 'description' => t("The author of the comment, if they were logged in."), + 'description' => t("The author name of the comment."), 'type' => 'user', ); @@ -173,9 +169,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements[$original] = $comment->url('edit-form', $url_options); break; - // @todo Remove 'name' token in favour of 'author'. See - // https://drupal.org/node/920056. - case 'name': case 'author': $name = $comment->getAuthorName(); $replacements[$original] = $sanitize ? Xss::filter($name) : $name; diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php index c3699aecb3f90cac8566bf7590e4d6a62da6f73e..462393b7a5a6ac3c6065ee95437103d431dc2eb8 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php @@ -51,7 +51,6 @@ function testCommentTokenReplacement() { $tests = array(); $tests['[comment:cid]'] = $comment->id(); $tests['[comment:hostname]'] = String::checkPlain($comment->getHostname()); - $tests['[comment:name]'] = Xss::filter($comment->getAuthorName()); $tests['[comment:author]'] = Xss::filter($comment->getAuthorName()); $tests['[comment:mail]'] = String::checkPlain($this->admin_user->getEmail()); $tests['[comment:homepage]'] = check_url($comment->getHomepage()); @@ -78,7 +77,6 @@ function testCommentTokenReplacement() { // Generate and test unsanitized tokens. $tests['[comment:hostname]'] = $comment->getHostname(); - $tests['[comment:name]'] = $comment->getAuthorName(); $tests['[comment:author]'] = $comment->getAuthorName(); $tests['[comment:mail]'] = $this->admin_user->getEmail(); $tests['[comment:homepage]'] = $comment->getHomepage(); @@ -93,6 +91,15 @@ function testCommentTokenReplacement() { $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input))); } + // Test anonymous comment author. + $author_name = $this->randomString(); + $comment->setOwnerId(0)->setAuthorName($author_name); + $input = '[comment:author]'; + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId())); + $this->assertEqual($output, Xss::filter($author_name), format_string('Sanitized comment author token %token replaced.', array('%token' => $input))); + $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); + $this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input))); + // Load node so comment_count gets computed. $node = node_load($node->id());