Problem/Motivation

Was reviewing the template_preprocess_comment() function's code and noticed a bug. The parent comment author was being built off the wrong comment.

  if ($comment->pid->target_id) {
    // Fetch and store the parent comment information for use in templates.
    $comment_parent = $comment->pid->entity;
    $account_parent = comment_prepare_author($comment);
    $variables['parent_comment'] = $comment_parent;
    $variables['parent_author'] = theme('username', array('account' => $account_parent));

Proposed resolution

comment_prepare_author($comment);
should be
comment_prepare_author($comment_parent);

#1857946: Comment parent template variables are built twice

Comments

joelpittet’s picture

StatusFileSize
new780 bytes
andymartha’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new73.26 KB

After applying patch 1990732-1-comment-parent.patch in #1 by joelpittet on a fresh Drupal 8 install, I detect that nothing broke and Drupal comments seem to function as normal through adding, viewing, and using them in Views.
commentparentafter1.png

joelpittet’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs manual testing

@andymartha thanks for having a look, should have posted manual testing instructions...

So this patch fixes the new hidden HTML element holding a parent comment in nested comments for accessibility reasons.

Steps to reproduce(should have wrote these before):

  1. Create nested comments and add a reply to a comment with a different author.
  2. Look in the code at the parent HTML being rendered inside the hidden element wrapper.

It should show the current author as the parent and the child author without the patch and different with the patch.

Hope that helps

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new62.02 KB
new48.99 KB

OK, I get it now. After applying patch 1990732-1-comment-parent.patch in #1 by joelpittet on a fresh Drupal 8 install, I detect that the patch changed the author from the original. See screenshots.

Before
Comment 1
-- Comment 2 replies to 1
-- Comment 3 replies to 2 (attributed to replies to 1)

After
Comment 1
-- Comment 2 replies to 1
-- Comment 3 replies to 2 (attributed to replies to 2)

commentparentbefore1.png

commentparentafter1.png

joelpittet’s picture

Wicked @andymartha! Thanks a lot for the review, that's the ticket!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b466d93 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.