Problem/Motivation

Part of #2010184: [meta] convert ‘uri_callback’ entities param to EntityInterface::uri() method

Current state: the functions is not used after #1970360-78: Entities should define URI templates and standard links

Deprecate comment_uri() function replacing it's calls to Comment::permalink() and clean-up Comment annotation uri_callback

Proposed resolution

- Update the comment_uri method to use Comment::permalink() instead of manually constructing the URL
- Deprecate comment_uri() in favor of Comment::permalink()

Remaining tasks

User interface changes

API changes

comment_uri() is deprecated.

Data model changes

Release notes snippet

Issue fork drupal-2010202

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

internetdevels’s picture

Assigned: internetdevels » Unassigned

.

kgoel’s picture

Status: Active » Needs review
StatusFileSize
new1.5 KB

Status: Needs review » Needs work

The last submitted patch, comment-2010202-2.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review

#2: comment-2010202-2.patch queued for re-testing.

tstoeckler’s picture

Status: Needs review » Needs work

This is missing the fragment. It should be kept like it was before.

garphy’s picture

StatusFileSize
new1.53 KB

Patch in #2 was not applying correctly anymore on HEAD. Rerolled.

garphy’s picture

Status: Needs work » Needs review

@tstoeckler, regarding #5, maybe it's up to the presentation layer to use ->permalink() instead of ->uri().

Entity::uri() should remain the canonical URI of the entity, without any fragment, no ?

tstoeckler’s picture

Status: Needs review » Needs work

I'm not really an expert on the whole comment URI / permalink question. But I remember that choosing this URI was discussed in-depth and had very specific reasoning (which I can't recall now). So if you think the fragment should not be part of the URL, please open another issue. For now, let's just straight port this. That would be awesome, thanks!

garphy’s picture

I would be glad to finish that as a straight port. Could you please recover some pointers referring to that discussion? I would be happy to get more insight on this.

garphy’s picture

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

This patch includes the fragment.

Status: Needs review » Needs work

The last submitted patch, comment-2010202-10.patch, failed testing.

andypost’s picture

Category: task » bug
Issue tags: +Needs tests

Actually after https://drupal.org/node/2020491 this function does not work because URI is generated via 'links' property and fragment is skipped
Not sure we need to override uri() method without checking $rel and calling parent::uri($rel)
Seems for 'canonical' is not allowed to have 'fragment'

berdir’s picture

See the original issue where this was added, it is not supported and was therefore dropped.

I don't rreally agree with that discussion/conclusion but that's what has been done.

andypost’s picture

Title: Convert comment_uri() to $comment->uri() » Remove comment_uri() as unused
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.09 KB

As we have $comment->permalink() and this code is not used anymore since #1970360-78: Entities should define URI templates and standard links

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

winning

jibran’s picture

andypost’s picture

Title: Remove comment_uri() as unused » Remove comment_uri() as unused and fix $comment->permalink()
Assigned: Unassigned » andypost
Status: Reviewed & tested by the community » Needs work
Issue tags: -Quick fix +DX (Developer Experience), +API clean-up

According #1978904-64: Convert comment_admin() to a Controller we have 3 different functions to generate permalink and comment/ID links to make DX better

andypost’s picture

Title: Remove comment_uri() as unused and fix $comment->permalink() » Remove comment_uri() as unused and fix $comment->permalink() to point to comment/123#comment-123

The proper fix for that should combine #2111419: Remove CommentManager::getParentEntityUri() in favor of Comment::permalink()

1) Comment->permalink() should point to actual comment comment/123#comment-123
2) Comment->getCommentedEntityURI() should point to node/1#comment-123

andypost’s picture

Title: Remove comment_uri() as unused and fix $comment->permalink() to point to comment/123#comment-123 » Fix Comment::permalink() and make links to comments usable
Status: Needs work » Postponed
andypost’s picture

Issue summary: View changes

related #1970360-78

sun’s picture

Title: Fix Comment::permalink() and make links to comments usable » Comment permalinks are lacking context and present a Usability regression (for e.g. drupal.org)
Priority: Normal » Major
Status: Postponed » Active
Issue tags: +Usability

Given how much of a regression D7's comment permalinks present for drupal.org (cf. #2125397: Enable comment_fragment 7.x-1.x-dev to improve issue comment permalinks), I definitely think we should fix this for D8.

What follows is essentially quoting myself from 2009: #26966-97: Fix comment links when paging is used.

The original change was meant to solve two discrete issues:

  1. Broken/dysfunctional links to comments that happen to be located on a subsequent page due to pager settings, whereas (i) pager settings can change at any time and (ii) new comments can move existing comments to a different page (in case comment threading is enabled).
  2. Preventing duplicate content indexed by search engines, caused by comment URLs.

(2) is fully resolved by canonical URI meta tags in core today. Any search engine that doesn't respect that is not worth to support.

(1) can be resolved in the exact same way, but more user-friendly today though:

/node/123?comment=456#comment-123

/{context_entity_type]/{context_entity_id}?comment={comment_id}#comment-{comment_id}
  1. The /comment/$id URI is replaced with the URI of the context.
  2. The requested comment is still targeted by a new ?comment=$id query string.
  3. The query string is used to conditionally redirect to the correct page (but in 99.9% of all cases, no redirect happens).
  4. Whoever plans to raise performance/caching concerns, especially with regard to reverse-proxies: The existing /comment/$id is a separate and separately cached URI, too: Zero difference.
  5. The fragment remains to jump to the right document position, even in case of a redirect.

Now, if you additionally take the architectural concern of comment #20 in #2113323-20: Rename Comment::permalink() to not be ambiguous with ::uri() into account, we actually arrive at this:

/{a/r/b/i/t/r/a/r/y/-/c/o/n/t/e/x/t}?comment={comment_id}#comment-{comment_id}

As a result, the most sane architecture and technical implementation I can think of is this:

  1. Turn Comment::permalink() into this:

    class Comment {
      public function uriByContext(\Drupal\Core\Url $context_uri) {
        $uri = clone $context_uri;
        $query = $uri->getOption('query');
        $query['comment'] = $this->id();
        $uri->setOption('query', $query);
        $uri->setOption('fragment', 'comment-' . $this->id());
        return $uri;
      }
    }
    
  2. Make {whichever-code} that generates the permalinks for comment fields attached to other entities call this:

    foreach ($comments as $comment) {
      $comment_permalink = $comment->uriByContext($this->entity->uri());
    }
    

    → resulting in e.g. /node/12345?comment=45678#comment-45678

  3. The real gist: Add a Request event subscriber to Comment module, which

    1. kicks-in for every Request that points to an entity resource URI (e.g. /node/12345)
    2. checks whether the request->query->has('comment')
    3. checks whether the requested comment is available on the requested URI
    4. if not, issues a redirect response (like now).

I originally planned to code this up myself, but I have too many other issues on my plate right now. My hope is that someone else is able to pick this up and turn this concept into an implementation.

andypost’s picture

The problem here that we need to query database in request subscriber to make sure that comment exists on given page.
Suppose this solvable except that this subscriber would fire on each entity route

catch’s picture

The query string is used to conditionally redirect to the correct page (but in 99.9% of all cases, no redirect happens).
Whoever plans to raise performance/caching concerns, especially with regard to reverse-proxies: The existing /comment/$id is a separate and separately cached URI, too: Zero difference.

That's not zero difference.

In one case you have a GET request which always returns a 200 and doesn't require any runtime checks. Sites with a relatively low number of comments per page will end up doing lots of 302 redirects, which is completely uncacheable.

Let's take a Drupal.org issue thread with over 300 comments, but which hasn't seen an update for several hours. Every time a comment link on the second page gets visited, whether by humans or crawlers, it'll always be a 302 whereas with the current scheme it'll be in varnish.

if not, issues a redirect response (like now).

There's no redirect in Drupal 7, there's a menu_execute_active_handler() call, and a subrequest in 8.x.

mgifford’s picture

Assigned: andypost » Unassigned

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 14: drupal8.comment-module.2010202-14.patch, failed testing.

larowlan’s picture

fil00dl’s picture

Here is my short review regarding the most popular "comment hosting services" :

FACEBOOK comments module :
All comments are visible on a single page with a « display n others comments » button displayed at the top. By default it display last comments and collapsing old ones.

DISQUS :
https://disqus.com/
All comments are visible on a single page with a « load more comments » button displayed at bottom.
permalink example : https://disqus.com/home/channel/selectstart/discussion/channel-selectsta...

LIVEFYRE :
All comments are visible on a single page with a “load comments” button displayed at bottom.
See example on http://mashable.com/ which implements this comment hosting service

MUUT :
https://muut.com/demos/basic-forum.html
All comments are visible on a single page with a “more” button displayed at bottom (the label of the button is a number which indicate the count of hidden comments).
permalink example : https://muut.com/demos/basic-forum.html#!/exhibitions:this-is-my-statement

DISCOURSE :
http://try.discourse.org/t/what-happens-when-a-topic-has-over-1000-repli...
All comments are visible on a single page through an infinite scroll :
Whether the user goes directly to a specific comment with the comment ID, the system will load the previous five and ten next comments which surrounds the specific comment.

WORDPRESS default comments system :
It displays all comments on a single page, without hiding the old ones.
permalink example : wordpress_site/2015/09/30/hello-world/#comment-5
All comments are displayed together, not possible to display a single comment with the permalink.

To sum up : with the modern "comment hosting services", there is never pagination for the comments display.
The more sophisticated solution is the “infinite scroll”.

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.

andypost’s picture

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

IS needs update cos deprecation of comment_uri() still makes sense, not sure as it bug

andypost’s picture

updated IS

andypost’s picture

StatusFileSize
new1.03 KB

Let's see effect of removal

andypost’s picture

StatusFileSize
new633 bytes

Added deprecation, CR still needed but let's see how often it's used

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Title: Comment permalinks are lacking context and present a Usability regression (for e.g. drupal.org) » Deprecate comment_uri()
Category: Bug report » Task
Issue tags: -Usability +Needs reroll

Updated the issue title, this is just a straightforward deprecation now. Needs a re-roll updating the deprecation version.

andypost’s picture

Issue tags: -Needs change record, -Needs reroll
StatusFileSize
new656 bytes

Filed CR https://www.drupal.org/node/3384294

and updated patch, looks there's no test for uri_callback annotation in comment entity

Also it needs update hook to clear entity definition cache, and let's see if something will be broken with deprecation only

Looking for better wording as Comment::permalink() is useless #2113323: Rename Comment::permalink() to not be ambiguous with ::uri()

That's reason why issue used to have such title

andypost’s picture

Issue summary: View changes

updated IS

catch’s picture

Comment::permalink() isn't useless, it's necessary to link to a comment in the context of the thread (with the correct page and comment fragment). I think we can just tell people to use that until it's renamed. However why not recommend $comment->uri() here?

samit.310@gmail.com made their first commit to this issue’s fork.

samitk’s picture

Status: Needs work » Needs review
Related issues: +#2667040: Deprecate uri_callback in routes for entities

Hello,

The comment_uri function is only been used in uri_callbackcomment entity's annotation.

As per https://www.drupal.org/project/drupal/issues/2667040 ticket the uri_callback is also depricated.

In template_preprocess_comment hook $comment->permalink(); is already been used to generate Comment link.

Thanks
Samit K.

smustgrave’s picture

Status: Needs review » Needs work

Title says to deprecate the function so that still needs to be done

samitk’s picture

Hi @smustgrave,

As per the changes record [#3384294] it is deprecated in 10.2.0 and will removed with 11.x, so i removed it for 11.x branch.

Thanks
Samit K.

samitk’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Yes but it got missed so now needs to be properly deprecated

samitk’s picture

Status: Needs work » Needs review

Hi @smustgrave,

Updated the code based on your suggestion. Also updated the changes record [#3384294].

Thanks
Samit K.

smustgrave’s picture

Status: Needs review » Needs work

Thanks only thing missing is a quick deprecation test

samitk’s picture

Status: Needs work » Needs review

Hi @smustgrave,,

Test also added, Please review.

Thanks
Samit K.

smustgrave’s picture

Status: Needs review » Needs work
samitk’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Needs work

Couple of minor questions/nits on MR, thanks for keeping this moving

shalini_jha made their first commit to this issue’s fork.

shalini_jha’s picture

Rebased & fixed the merge conflict, looking into the MR feedback.

shalini_jha’s picture

Status: Needs work » Needs review

I have reviewed all the feedback and made the necessary updates. After making the changes, I re-ran the tests, and This is working as expected. Moving this to NR for your review.

smustgrave’s picture

Status: Needs review » Needs work

Left another small comment on MR.

shalini_jha’s picture

Assigned: Unassigned » shalini_jha

I am working on it

shalini_jha’s picture

Assigned: shalini_jha » Unassigned
Status: Needs work » Needs review

@smustgrave Thank you for the review & feedback , I have updated the test file name and comment for the test class, Accordingly updated the Phpstan baseline . Re-run test after these changes and working as expected. and pipeline is green so moving this again for your review.
Kindly review.

smustgrave’s picture

Status: Needs review » Needs work

Left 1 more comment on the thread started by @larowlan

shalini_jha’s picture

Status: Needs work » Needs review

Moving this for your review.

shalini_jha’s picture

Removed the comment on the return statement, as I believe it was not appropriate.
Kindly review.

berdir’s picture

Status: Needs review » Needs work

This function is still referenced on the Comment entity type attribute as the uri callback, it should be removed there. https://git.drupalcode.org/project/drupal/-/blob/010bbc7476df8c23b0170f5...

shalini_jha’s picture

Status: Needs work » Needs review

@berdir Thank you for the feedback , I have removed the uri_callback and tested the functionality. It is working as expected. However, I am a bit unsure if there is anything else that needs to be updated related to this.

Moving this for NR , Kindly review.

berdir’s picture

Yes, uri_callback has not actually been used in a very, very long time. If it would have been called, it would have triggered deprecation errors in the tests. Looking at \Drupal\Core\Entity\EntityBase::toUrl(), it only falls back to that if there are no link templates defined. Which isn't the case for the comment entity (or any other entity in core AFAIK).

shalini_jha’s picture

@berdir, Thank you for the Information :)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Believe all feedback for this one has been addressed.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

I read the IS, comments and the MR. This all looks good but I found some things that need work, so setting to NW. See the comments in the MR.

I am not sure about the removal of uri_callback: 'comment_uri',. I did read the comment from @berdir but it is used in entity.api.php and other files. I think that needs some investigation.

berdir’s picture

the proposed solution in the iS does need an update, but #72 explains why it's not called. uri_callback is a weird leftover from before we had link templates.

Entirely deprecating that concept is done in #2667040: Deprecate uri_callback in routes for entities, this is just one specific dead configuration that is not used.

shalini_jha’s picture

Status: Needs work » Needs review

Addressed all the feedback. Based on #75, I have checked the uri_callback: 'comment_uri' in other places. I found it in EntityInterface.php. Do we need to update this as well?

Based on #76 detail, I am moving this to Needs Review to get confirmation.

smustgrave’s picture

Status: Needs review » Needs work

@shalini_jha big thing it was sent back for seems to be issue summary update which still appears to be needed

shalini_jha’s picture

Ah yes i missed to this IS update tag , sorry for the inconvenience, i am working for this.

shalini_jha’s picture

Issue summary: View changes
shalini_jha’s picture

1 usage in contrib found http://grep.xnddx.ru/search?text=comment_uri&filename=
Removed this line as given url is not working

shalini_jha’s picture

Issue summary: View changes
shalini_jha’s picture

I Have updated the issue summary based on the changes we have done so far. waiting for the confirmation of removal of uri_callback from other place.

longwave made their first commit to this issue’s fork.

longwave’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs issue summary update

#2010132: Canonical taxonomy term link for forum vocabulary is broken reminded me of this; forum is removing use of uri_callback, once comment does as well then it can be removed from core entirely.

Rebased the MR, updated the deprecation for 11.3, updated issue credit, I think this is ready to go.

Removed these from the IS as they already exist as followups:

#2113323: Rename Comment::permalink() to not be ambiguous with ::uri()
#2667040: Deprecate uri_callback in routes for entities

longwave’s picture

Issue summary: View changes

  • catch committed a3668342 on 11.x
    Issue #2010202 by shalini_jha, samit.310@gmail.com, andypost, garphy,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

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