Problem/Motivation

1. Installed Drupal 8.0.1
2. Created an article.
3. Posted some comments to the article.

Expected - the comment title should link to the comment fragment. /comment/123#comment-123
Actual - the comment title just points to /comment/123

Proposed resolution

Include the fragment to the comment in the link.
At #29 was decided to use the Permalink function instead of just add the fragment.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gargsuchi created an issue. See original summary.

gargsuchi’s picture

FileSize
509 bytes

The attached patch fixes this problem.

gargsuchi’s picture

Issue summary: View changes
gnuget’s picture

Status: Active » Needs work

Hi!

This looks good! but with the txt extension this patch won't be tested by the testbot.

Can you please re-upload your patch using the guidelines? https://www.drupal.org/node/707484

Thanks!

gargsuchi’s picture

gnuget’s picture

Status: Needs work » Needs review
gnuget’s picture

Status: Needs review » Reviewed & tested by the community

Testbot didn't complain so this is RTBC to me.

Thanks!

Wim Leers’s picture

Component: entity system » comment.module
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This needs test coverage to prevent future regressions.

gnuget’s picture

Assigned: gargsuchi » Unassigned
Status: Needs work » Needs review
FileSize
1.65 KB

OK, In this new patch I added the test.

Status: Needs review » Needs work

The last submitted patch, 9: comments_title_link-2642260-9.patch, failed testing.

The last submitted patch, 9: comments_title_link-2642260-9.patch, failed testing.

gnuget’s picture

Status: Needs work » Needs review
FileSize
1.59 KB

Not sure why the testbot fails here, I tried with a slightly different approach this time

Wim Leers’s picture

Can you provide an interdiff? It's difficult to figure out what's changed.

gnuget’s picture

FileSize
1.11 KB

Sure, this is the interdiff between #9 and #12

Thanks for your time.

lokapujya’s picture

  1. +++ b/core/modules/comment/src/Tests/CommentTitleTest.php
    @@ -65,9 +65,8 @@ public function testCommentPopulatedTitles() {
    -    $comment_permalink = (string)$comment_permalink[0]->attributes()->{'href'};
    ...
    +    $comment_permalink = (string)$comment_permalink[0]['href'];
    

    I guess this was the fix to the test?

  2. +++ b/core/modules/comment/src/Tests/CommentTitleTest.php
    @@ -65,9 +65,8 @@ public function testCommentPopulatedTitles() {
    +    $this->assertTrue((bool)preg_match('/\/comment\/[0-9]+#comment\-[0-9]+/', $comment_permalink), 'The comment\'s title has the correct link');
    

    It's no longer testing that the title has the correct link. Now it's testing that the comment includes a fragment.

gnuget’s picture

Ok,I just added the comment id just to make sure to we are testing the correct link.

Thanks for your review!

lokapujya’s picture

I'll leave it up to you, but maybe we don't need to use the preg_match anymore if that works?

gnuget’s picture

lokapujya’s picture

Status: Needs review » Reviewed & tested by the community
amateescu’s picture

Title: Comments Title link missing fragment » Missing URL fragment for the comment's title link
Version: 8.0.1 » 8.0.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests

Just tested this manually and it is indeed a regression from D7.

The patch looks pretty good, I only found two small things that could be fixed:

  1. +++ b/core/modules/comment/src/Tests/CommentTitleTest.php
    @@ -64,5 +64,9 @@ public function testCommentPopulatedTitles() {
    +    $comment_permalink = (string)$comment_permalink[0]['href'];
    

    Missing space after "(string)".

  2. +++ b/core/modules/comment/src/Tests/CommentTitleTest.php
    @@ -64,5 +64,9 @@ public function testCommentPopulatedTitles() {
    +    $this->assertTrue('/comment/' . $comment1->id() . '#comment-' . $comment1->id() ==  $comment_permalink, 'The comment\'s title has the correct link');
    

    We should use assertEqual() here :)

lokapujya’s picture

#20.2 now that you mention it, assertLinkByHref() may be an option too.

gnuget’s picture

Status: Needs work » Needs review
FileSize
1.6 KB
1.01 KB

Thanks for your reviews.

Here the patch with the changes.

I considered using assertLinkByHref but in this particular page we might have the same link twice (see #2641682: permalink breaks in comment) so I prefer to look for this specific link in the title of the comment, thanks for your suggestion, I didn't know about this function.

The last submitted patch, 18: comments_title_link-2642260-18.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 22: comments_title_link-2642260-22.patch, failed testing.

gnuget’s picture

This is weird, #18 passed before and now it failed, and #22 passed in my local version :-/

And looking at https://www.drupal.org/pift-ci-job/155572 what is that "checkout" think in the URL?

is this might be a malfunctioning of the bot? am I doing something wrong?

gnuget’s picture

gnuget’s picture

Status: Needs work » Needs review

Lets see if this time I can make happy the testbot

lokapujya’s picture

Status: Needs review » Reviewed & tested by the community
Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

#25: #18 was likely a false positive due to #2657482: Test bot doesn't apply the patch.


The logic in template_preprocess_comment() is now actually making it a permalink… which means it can use $comment->permalink(), just like $variables['permalink'] already does.

+++ b/core/modules/comment/comment.module
@@ -660,6 +660,7 @@ function template_preprocess_comment(&$variables) {
     $uri->setOption('attributes', $attributes);
+    $uri->setOption('fragment', 'comment-' . $comment->id());
     $variables['title'] = \Drupal::l($comment->getSubject(), $uri);

This is nearly equal to

  public function permalink() {
    $entity = $this->getCommentedEntity();
    $uri = $entity->urlInfo();
    $uri->setOption('fragment', 'comment-' . $this->id());
    return $uri;
  }

The only difference is the $uri->setOption('attributes', $attributes); call.

So, this patch can hence AFAICT be simplified to:

diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index e1d74b6..a91c0ec
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -656,7 +656,7 @@ function template_preprocess_comment(&$variables) {
     $variables['permalink'] = \Drupal::l(t('Permalink'), new Url('<front>'));
   }
   else {
-    $uri = $comment->urlInfo();
+    $uri = $comment->permalink();
     $attributes = $uri->getOption('attributes') ?: array();
     $attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
     $uri->setOption('attributes', $attributes);
gnuget’s picture

Status: Needs work » Needs review

While I'm agree with you about to we should use the permalink here instead of just add the fragment to the url the thing is the permalink function is broken.

The $comment->permalink(); returns /node/1#comment-1 which is not a the permalink because this function doesn't consider the pagination of the nodes, indeed this was already reported in #2641682: permalink breaks in comment

So in my opinion what we need to do is pospone this issue fix #2641682: permalink breaks in comment and later come back to this one and use $comment->permalink(); this time.

What do you think?

Wim Leers’s picture

Works for me!

gnuget’s picture

Status: Needs review » Postponed

Alright, let's do that.

gnuget’s picture

Assigned: Unassigned » gnuget
Status: Postponed » Active

Alright #2641682: permalink breaks in comment was fixed now we can continue working on this one.

I will assign it to me.

gnuget’s picture

Version: 8.0.x-dev » 8.1.x-dev
Assigned: gnuget » Unassigned
Status: Active » Needs review
FileSize
1.97 KB
1.54 KB

Ok in this new patch I used the permalink function.

gnuget’s picture

Issue summary: View changes
dinarcon’s picture

The patch at number at #34 needed reroll. I have done that and tested it. It looks good. Thanks @gnuget!

larowlan’s picture

+++ b/core/modules/comment/src/Tests/CommentTitleTest.php
@@ -59,6 +59,10 @@ public function testCommentPopulatedTitles() {
+    $this->assertEqual($comment1->permalink()->toString(), $comment_permalink, 'The comment\'s title has the correct link');

minor: can we just use double quotes here instead of \'?

Should we also check that the href includes the fragment?

Other than that, looks RTBC to me

gnuget’s picture

Version: 8.1.x-dev » 8.2.x-dev
FileSize
1002 bytes
1.75 KB
naveenvalecha’s picture

Hiding #39 patches

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks - #38 is RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 39: 2642260-38.patch, failed testing.

gnuget’s picture

Status: Needs work » Reviewed & tested by the community

I return this to RTBC because the patch which failed was #39 and the patch RTBC is 38. (and I just make sure and it still applies correctly)

  • catch committed 0515e65 on 8.3.x
    Issue #2642260 by gnuget, gargsuchi, naveenvalecha, dinarcon: Missing...

  • catch committed b5b2356 on 8.2.x
    Issue #2642260 by gnuget, gargsuchi, naveenvalecha, dinarcon: Missing...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

cilefen’s picture

Can somebody please close #2793373: permalink for comments not working if it is a duplicate?

Wim Leers’s picture

@cilefen: done.

Status: Fixed » Closed (fixed)

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