Problem/Motivation

Comment preview page previewed new comment links are broken / not user friendly.

To reproduce the bug:

  1. Fill the comment form and go to preview.
  2. Click the linked comment subject in the comment preview.
  • In D6 the link is an anchor inside the same page.
  • In D7 the link point to "comment/#comment-" that is not a valid page (page not found).
  • In D8 the link has been changed to

Proposed resolution

  • Link the new comment title on a comment preview page to the current page with an anchor tag.
  • Link the new comment permalink on a comment preview page to the current page with an anchor tag.

Remaining tasks

  • Patch for D8
  • Backport for D7

User interface changes

Comment preview page new comment links will keep user on the preview page.

API changes

N/A

Comments

peximo’s picture

The problem seem to be that in comment preview there isn't the $comment->cid used in template_preprocess_comment() to create the link.
$variables['title'] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => "comment-$comment->cid"));

dawehner’s picture

I guess the only way to "solve" this is to show no link, if the cid is not available.

peximo’s picture

StatusFileSize
new1.08 KB

This patch fix the problem; obviously the subject appearance in the preview is different than that in the node view.

dawehner’s picture

Status: Active » Needs review

Update status

Status: Needs review » Needs work

The last submitted patch, comment_subject-655410-3.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB

Set the right unix format.

MichaelCole’s picture

#6: comment_subject-655410-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, comment_subject-655410-6.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB

I don't think we need to modify comment_uri(). Rerolled.

retester2010’s picture

Status: Needs review » Needs work
+++ modules/comment/comment.module	3 May 2010 12:54:24 -0000
@@ -2172,10 +2172,15 @@ function template_preprocess_comment(&$v
+  }
+  ¶

trailing white space

Powered by Dreditor.

peximo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, comment_subject-655410-11.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.23 KB

Updated and rerolled.

Status: Needs review » Needs work

The last submitted patch, comment_subject-655410-13.patch, failed testing.

peximo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB
rschwab’s picture

Status: Needs review » Reviewed & tested by the community

The patch still applies to latest dev, fixes the problem, and adheres to coding standards as I understand them. dereine do you agree this is RTBC?

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Tests please.

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

I can still reproduce this using Drupal 7.2.

dawehner’s picture

+++ modules/comment/comment.module	8 Oct 2010 12:20:27 -0000
@@ -2219,9 +2219,17 @@ function template_preprocess_comment(&$v
+  else {
+    $uri = array(
+      'path' => $_GET['q'],
+      'options' => array('attributes' => array(), 'fragment' => ' '),

This code should better be explained here.

In general the solution in #1048494: No title or wrong title in preview should be synced with this one, even it's not 100% sure which one is the better one.

andypost’s picture

Issue summary: View changes
Issue tags: +Needs reroll
Related issues: +#2113323: Rename Comment::permalink() to not be ambiguous with ::uri()
kerby70’s picture

Current Drupal 8.0.x-dev comment.module code creates the preview title link to front. Does this resolve this issue for D8?

  if (isset($comment->in_preview)) {
    $variables['title'] = \Drupal::l($comment->getSubject(), new Url('<front>'));
    $variables['permalink'] = \Drupal::l(t('Permalink'), new Url('<front>'));
  }
  else {
    $uri = $comment->urlInfo();
    $attributes = $uri->getOption('attributes') ?: array();
    $attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
    $uri->setOption('attributes', $attributes);
    $variables['title'] = \Drupal::l($comment->getSubject(), $uri);

    $variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink());
  }
andypost’s picture

I think it makes sense to provide a real link when comment not new (when preview called for edit comment form)
And yes this needs tests and total rewrite because code is changed

larowlan’s picture

Why not make the link to #? i.e. remain in the preview

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new911 bytes

Good idea, comments in preview always have #new marker, so here's a new patch
Let's see the tests coverage

andypost’s picture

Issue tags: -Needs reroll
kerby70’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

#24 looks great. Both links remain on the current page form the comment preview page.

I am updating the summary for better clarity.

kerby70 queued 24: 655410-24.patch for re-testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Still needs tests

lakshminp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB

added test case.

andypost’s picture

Status: Needs review » Needs work

please file a separete patch with test only to make sure that test fails without patch

lakshminp’s picture

StatusFileSize
new655 bytes

patched with just the test alone.

andypost’s picture

Status: Needs work » Needs review

Let's see

Status: Needs review » Needs work

The last submitted patch, 31: 655410-31.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests

so "fail" is valid, please name the patch next time "patch_name-fail.patch"

xjm’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup
StatusFileSize
new19.25 KB

Thanks for the test-only patch and the clear issue summary!

I thought we added something that made links in previews not take the user out of the preview a long time ago... I guess it was only the node preview. Since then the "real" preview functionality has improved it further and does this:

I agree with fixing this the "quick" way for now as it improves the usability slightly; linking to the front page is definitely wrong. In another issue though, we should explore using the same preview mechanism we have for nodes. Maybe for 8.1.x, though as a usability improvement it might even be acceptable for 8.0.x.

However, I don't think the approach in this patch is correct. When I preview a comment, the #new fragment ID does not even appear on the page, so they are just broken no-op links. It might as well be a link to #. Also, there are still other links on the page that can take the user out of the preview, like the username link, or any menu item for that matter since it's not considered an admin path the way that node preview is.

Maybe for an interim fix we should dig out the earlier patch for node preview links and use that fix -- I think it added some javascript or something to make all the links on the whole preview page not do anything? Failing that, I'd prefer to just link to # rather than a non-existent fragment ID. But let's at least try to find the previous issue and add it to the related issues.

  1. +++ b/core/modules/comment/comment.module
    @@ -641,8 +641,11 @@ function template_preprocess_comment(&$variables) {
    +    // Link title and permalink to current page because comment could not be
    +    // saved now and we should not allow user to leave the page.
    

    Less important, but this comment confuses me a little. "Comment could not be saved now" doesn't seem correct. Maybe "Use the current page for the title and permalink in the preview, so that the user does not accidentally leave the page and lose work."

  2. +++ b/core/modules/comment/src/Tests/CommentPreviewTest.php
    @@ -62,6 +62,9 @@ function testCommentPreview() {
    +    // Check that the permalink and subject link has #new fragment
    

    Minor: missing period at the end of the comment.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.35 KB
new2.56 KB

Rerolled and refactored, we are changing two links, so expanded the test coverage to cover both.

Since @xjm pointed out that this wasn't the best way of fixing this, not sure how valid this still is.

rinku jacob 13’s picture

StatusFileSize
new271.4 KB
new231.85 KB
new101.62 KB
new68.82 KB

I have successfully applied patch #47 for drupal 9.4.x-dev. thanks @Lendude

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Holy cow 13 years...

Testing on Drupal10.1 I can confirm the issue is still there. The subject link goes to the homepage which just doesn't make sense.

Applying the patch from #47 the link is now #new which is MUCH better.
Triggering D10 tests

If those pass I'll mark it.

smustgrave’s picture

Status: Needs review » Needs work

Seems to have test failures that are valid.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.