diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index 9101217..2cd0578 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -136,7 +136,7 @@ class EntityRenderController implements EntityRenderControllerInterface { $this->alterBuild($build[$key], $entity, $entity_view_mode, $langcode); $build[$key]['#weight'] = $weight++; - // Allow modules to modify the structured comment. + // Allow modules to modify the structured entity. drupal_alter(array($view_hook, 'entity_view'), $build[$key], $entity); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0cb707e..ee40f73 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -769,7 +769,7 @@ function comment_node_page_additions(Node $node) { if ($cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); comment_prepare_thread($comments); - $build = comment_view_multiple($comments, $node); + $build = comment_view_multiple($comments); $build['pager']['#theme'] = 'pager'; $additions['comments'] = $build; } @@ -969,8 +969,6 @@ function comment_prepare_thread(&$comments) { * * @param Drupal\comment\Comment $comment * The comment object. - * @param Drupal\node\Node $node - * The node the comment is attached to. * @param $view_mode * View mode, e.g. 'full', 'teaser'... * @param $langcode @@ -980,8 +978,7 @@ function comment_prepare_thread(&$comments) { * @return * An array as expected by drupal_render(). */ -function comment_view(Comment $comment, Node $node, $view_mode = 'full', $langcode = NULL) { - $comment->node = $node; +function comment_view(Comment $comment, $view_mode = 'full', $langcode = NULL) { return entity_view($comment, $view_mode, $langcode); } @@ -1051,12 +1048,8 @@ function comment_links(Comment $comment, Node $node) { * * @param $comments * An array of comments as returned by comment_load_multiple(). - * @param Drupal\node\Node $node - * The single node the comments are attached to. * @param $view_mode * View mode, e.g. 'full', 'teaser'... - * @param $weight - * An integer representing the weight of the first comment in the list. * @param $langcode * A string indicating the language field values are to be shown in. If no * language is provided the current content language is used. @@ -1066,9 +1059,8 @@ function comment_links(Comment $comment, Node $node) { * * @see drupal_render() */ -function comment_view_multiple($comments, Node $node, $view_mode = 'full', $weight = 0, $langcode = NULL) { - reset($comments)->node = $node; - return entity_view_multiple($comments, $view_mode, $weight, $langcode); +function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) { + return entity_view_multiple($comments, $view_mode, $langcode); } /** @@ -1306,7 +1298,7 @@ function comment_node_update_index(Node $node, $langcode) { if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); comment_prepare_thread($comments); - $build = comment_view_multiple($comments, $node, $langcode); + $build = comment_view_multiple($comments, $langcode); return drupal_render($build); } } @@ -1534,7 +1526,7 @@ function comment_get_display_ordinal($cid, $node_type) { else { // For threaded comments, the c.thread column is used for ordering. We can // use the sorting code for comparison, but must remove the trailing slash. - // See comment_view_multiple(). + // See CommentRenderController. $query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) -1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) -1))'); } @@ -1582,7 +1574,6 @@ function comment_edit_page(Comment $comment) { function comment_preview(Comment $comment) { global $user; $preview_build = array(); - $node = node_load($comment->nid); if (!form_get_errors()) { $comment->format = $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['format']; @@ -1608,7 +1599,7 @@ function comment_preview(Comment $comment) { $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME; $comment->changed = REQUEST_TIME; $comment->in_preview = TRUE; - $comment_build = comment_view($comment, $node); + $comment_build = comment_view($comment); $comment_build['#weight'] = -100; $preview_build['comment_preview'] = $comment_build; @@ -1618,11 +1609,11 @@ function comment_preview(Comment $comment) { $build = array(); $comment = comment_load($comment->pid); if ($comment && $comment->status == COMMENT_PUBLISHED) { - $build = comment_view($comment, $node); + $build = comment_view($comment); } } else { - $build = node_view($node); + $build = node_view(node_load($comment->nid)); } $preview_build['comment_output_below'] = $build; diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index ed91d23..3d1ecb9 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -68,7 +68,7 @@ function comment_reply(Node $node, $pid = NULL) { $comment->node_type = 'comment_node_' . $node->type; field_attach_load('comment', array($comment->cid => $comment)); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $build['comment_parent'] = comment_view($comment, $node); + $build['comment_parent'] = comment_view($comment); } else { drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php index abb79f4..58f8315 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php @@ -30,14 +30,9 @@ class CommentRenderController extends EntityRenderController { // Array is known not be empty, and all comments apply to the same node, // so we can just fetch the node from the first comment. $entity = reset($entities); - if (isset($entity->node)) { - $node = $entity->node; - } - else { - $node = node_load($entity->nid); - if (empty($node)) { - throw new \InvalidArgumentException(t('Invalid node for comment.')); - } + $node = node_load($entity->nid); + if (empty($node)) { + throw new \InvalidArgumentException(t('Invalid node for comment.')); } foreach ($entities as $entity) { @@ -49,6 +44,12 @@ class CommentRenderController extends EntityRenderController { parent::buildContent($entities, $view_mode, $langcode); foreach ($entities as $entity) { + $node = node_load($entity->nid); + if (!$node) { + throw new \InvalidArgumentException(t('Invalid node for comment.')); + } + $entity->content['#node'] = $node; + $entity->content['#theme'] = 'comment__node_' . $node->bundle(); $entity->content['links'] = array( '#theme' => 'links__comment', '#pre_render' => array('drupal_pre_render_links'), @@ -58,7 +59,7 @@ class CommentRenderController extends EntityRenderController { $entity->content['links'][$this->entityType] = array( '#theme' => 'links__comment__comment', // The "node" property is specified to be present, so no need to check. - '#links' => comment_links($entity, $entity->node), + '#links' => comment_links($entity, $node), '#attributes' => array('class' => array('links', 'inline')), ); } @@ -66,19 +67,6 @@ class CommentRenderController extends EntityRenderController { } /** - * Overrides Drupal\Core\Entity\EntityRenderController::getBuildDefaults(). - */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { - $return = parent::getBuildDefaults($entity, $view_mode, $langcode); - // @todo Accessing $node on an EntityInterface is not clean. Maybe we want - // to define some extended interface exposing node. - $node = $entity->node; - $return['#theme'] = 'comment__node_' . $node->bundle(); - $return['#node'] = $node; - return $return; - } - - /** * Overrides Drupal\Core\Entity\EntityRenderController::alterBuild(). */ protected function alterBuild(array &$build, EntityInterface $comment, $view_mode, $langcode = NULL) { diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php index 980efc7..2674152 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php @@ -39,7 +39,7 @@ class CommentContentRebuildTest extends CommentTestBase { // Add the property to the content array and then see if it still exists on build. $comment_loaded->content['test_property'] = array('#value' => $this->randomString()); - $built_content = comment_view($comment_loaded, $this->node); + $built_content = comment_view($comment_loaded); // This means that the content was rebuilt as the added test property no longer exists. $this->assertFalse(isset($built_content['test_property']), 'Comment content was emptied before being built.');