Problem/Motivation

Comment links used to look like this:

/node/17#comment-42

Let's call this the classic comment link. In general it does not work—never did, except if the comment happened to be on the very first page of a node display.

Drupal 7 has, thankfully, been fixed, however, the fix works only with new-format comment links that look like this:

/node/17?comment=42#comment-42

The reason for this, is that Drupal on the server (i.e. PHP in general) has no way of reading the hash part of the URL, so it has to be duplicated in the query/search part.

All preexisting classic links all over the world still don't work properly and never will, unless we do something about it.

Proposed resolution

A simplified version of the working code for issue #677082: Comment links - JavaScript solution could be used to allow foreign links, i.e. classic comment links on non-Drupal pages to work. This would work as follows.

  1. User clicks on classic comment link on a non-Drupal web page.
  2. The Drupal server cannot process this link properly and opens the very first page.
  3. Once the page is open, the JavaScript code checks the link and discovers that it is a classic comment link.
  4. The JavaScript program looks at the hash part of the URL (yes, JavaScript can do that) and checks whether the targetted comment is indeed on the current page.
  5. If not, the program reformats the link to the new format and calls up the page again, this time with the proper comment query included.
  6. Now that Drupal learns about the desired comment, it opens the proper page.

This requires two page calls in the hopefully infrequent case that the desired comment happens not to be on the first page.

Remaining tasks

patch

User interface changes

JS based URL redirection for "classic" comment links to the current format for pagination

API changes

none

Original report by @hgmichna

...

(Not to be mixed up with Creedence Clearwater Revival :-)

I'm proposing this for 7.x-dev, because it is closely related to issue #26966: Fix comment links when paging is used., which has recently been closed with success, and because it is a very small change that does hardly interfere with existing code. If not that, let it go for 8.x-dev.

....

An odd recognition on the side is that we could use much simpler, nicer links that look almost like the classic ones:

/node/17?comment=42

An additional, even smaller piece of JavaScript would have to look at the URL after the page is loaded and jump down to the desired comment, just as the browser does on its own when presented with the hash part, #comment-42. Very similar code already exists in issue #677082: Comment links - JavaScript solution, so there wouldn't even be much work to do. I think it can't hurt to add that bit of code as well. Perhaps in a few years that could become the most favored comment link format.

Nothing would preclude the continued use of the additional, redundant hash part, so these formats could exist side by side.

...

CommentFileSizeAuthor
#2 drupal.comment-paging-js.2.patch2.37 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Title: Classic Comment Link Revival » Old-school comment URL #fragments still don't display correct page
Component: base system » comment.module
Category: feature » task

#677082: Comment links - JavaScript solution has been marked as duplicate, contained a link to example code.

sun’s picture

Status: Active » Needs review
FileSize
2.37 KB
hgmichna’s picture

Great! Thanks. And it's such a compact piece of JavaScript code.

Good job! Sometimes JavaScript can help to solve the trickiest problems.

I'll bite my tongue and swallow my comment on jQuery use (:-). But the thing has already hooked on to Drupal anyway.

thedavidmeister’s picture

Issue summary: View changes
thedavidmeister’s picture

Version: 7.x-dev » 8.x-dev
Category: Task » Bug report
Status: Needs review » Needs work

I'm going to pull this forward to D8 and it will need a backport if/when committed there.

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

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.

catch’s picture

Status: Needs work » Closed (outdated)

It probably would have made sense to fix this in 2010, but we haven't been producing old-style comment links for over 15 years now, so there are probably not many left even as ancient linkrot. Marking outdated.