From 26a0068b82024009e76d3001961faa6af7603900 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Wed, 12 Nov 2014 17:21:07 +0000 Subject: [PATCH] Issue #2031901 by andypost: Remove node tokens from comment.tokens.inc. --- core/modules/comment/comment.tokens.inc | 33 ++----------------- .../src/Tests/CommentTokenReplaceTest.php | 11 +++---- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 8f6d0083635..a1b2cd77ad9 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -83,13 +83,6 @@ function comment_token_info() { 'description' => t("The entity the comment was posted to."), 'type' => 'entity', ); - // Support legacy comment node tokens, since tokens are embedded in user data - // and can't be upgraded directly. - $comment['node'] = array( - 'name' => t("Node"), - 'description' => t("DEPRECATED: The node the comment was posted to."), - 'type' => 'node', - ); $comment['author'] = array( 'name' => t("Author"), 'description' => t("The author name of the comment."), @@ -101,8 +94,6 @@ function comment_token_info() { 'tokens' => array( 'entity' => $entity, 'comment' => $comment, - // Support deprecated node tokens. - 'node' => $entity, ), ); } @@ -194,20 +185,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $title = $entity->label(); $replacements[$original] = $sanitize ? Xss::filter($title) : $title; break; - - case 'node': - // Support legacy comment node tokens, since tokens are embedded in - // user data and can't be upgraded directly. - // @todo Remove in Drupal 9, see https://drupal.org/node/2031901. - if ($comment->getCommentedEntityTypeId() == 'node') { - $entity = $comment->getCommentedEntity(); - $title = $entity->label(); - $replacements[$original] = $sanitize ? Xss::filter($title) : $title; - } - else { - $replacements[$original] = NULL; - } - break; } } @@ -217,11 +194,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements += $token_service->generate($comment->getCommentedEntityTypeId(), $entity_tokens, array($comment->getCommentedEntityTypeId() => $entity), $options); } - if (($node_tokens = $token_service->findwithPrefix($tokens, 'node')) && $comment->getCommentedEntityTypeId() == 'node') { - $node = $comment->getCommentedEntity(); - $replacements += $token_service->generate('node', $node_tokens, array('node' => $node), $options); - } - if ($date_tokens = $token_service->findwithPrefix($tokens, 'created')) { $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->getCreatedTime()), $options); } @@ -238,10 +210,9 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements += $token_service->generate('user', $author_tokens, array('user' => $account), $options); } } - elseif (($type == 'entity' & !empty($data['entity'])) || - ($type == 'node' & !empty($data['node']))) { + elseif ($type == 'entity' & !empty($data['entity'])) { /** @var $entity \Drupal\Core\Entity\FieldableEntityInterface */ - $entity = !empty($data['entity']) ? $data['entity'] : $data['node']; + $entity = $data['entity']; foreach ($tokens as $name => $original) { switch ($name) { diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php index fa836872023..2bf97f878e3 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php @@ -63,8 +63,10 @@ class CommentTokenReplaceTest extends CommentTestBase { $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->getId()); $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL; $tests['[comment:parent:title]'] = String::checkPlain($parent_comment->getSubject()); - $tests['[comment:node:nid]'] = $comment->getCommentedEntityId(); - $tests['[comment:node:title]'] = String::checkPlain($node->getTitle()); + $tests['[comment:entity]'] = String::checkPlain($node->getTitle()); + // Test node specific tokens. + $tests['[comment:entity:nid]'] = $comment->getCommentedEntityId(); + $tests['[comment:entity:title]'] = String::checkPlain($node->getTitle()); $tests['[comment:author:uid]'] = $comment->getOwnerId(); $tests['[comment:author:name]'] = String::checkPlain($this->admin_user->getUsername()); @@ -84,7 +86,7 @@ class CommentTokenReplaceTest extends CommentTestBase { $tests['[comment:title]'] = $comment->getSubject(); $tests['[comment:body]'] = $comment->comment_body->value; $tests['[comment:parent:title]'] = $parent_comment->getSubject(); - $tests['[comment:node:title]'] = $node->getTitle(); + $tests['[comment:entity]'] = $node->getTitle(); $tests['[comment:author:name]'] = $this->admin_user->getUsername(); foreach ($tests as $input => $expected) { @@ -108,9 +110,6 @@ class CommentTokenReplaceTest extends CommentTestBase { $tests = array(); $tests['[entity:comment-count]'] = 2; $tests['[entity:comment-count-new]'] = 2; - // Also test the deprecated legacy token. - $tests['[node:comment-count]'] = 2; - $tests['[node:comment-count-new]'] = 2; foreach ($tests as $input => $expected) { $output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId()));