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
| Comment | File | Size | Author |
|---|
Issue fork drupal-2010202
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:
- 2010202-deprecate-commenturi
changes, plain diff MR !9423
Comments
Comment #1
internetdevels commented.
Comment #2
kgoel commentedComment #4
kgoel commented#2: comment-2010202-2.patch queued for re-testing.
Comment #5
tstoecklerThis is missing the fragment. It should be kept like it was before.
Comment #6
garphyPatch in #2 was not applying correctly anymore on HEAD. Rerolled.
Comment #7
garphy@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 ?
Comment #8
tstoecklerI'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!
Comment #9
garphyI 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.
Comment #10
garphyThis patch includes the fragment.
Comment #12
andypostActually 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'
Comment #13
berdirSee 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.
Comment #14
andypostAs we have
$comment->permalink()and this code is not used anymore since #1970360-78: Entities should define URI templates and standard linksComment #15
larowlanwinning
Comment #16
jibran#1978904: Convert comment_admin() to a Controller needs a reroll then.
Comment #17
andypostAccording #1978904-64: Convert comment_admin() to a Controller we have 3 different functions to generate permalink and
comment/IDlinks to make DX betterComment #18
andypostThe proper fix for that should combine #2111419: Remove CommentManager::getParentEntityUri() in favor of Comment::permalink()
1)
Comment->permalink()should point to actual commentcomment/123#comment-1232)
Comment->getCommentedEntityURI()should point tonode/1#comment-123Comment #19
andypostMarked #2111419: Remove CommentManager::getParentEntityUri() in favor of Comment::permalink() as duplicate
Postponing on #2113323: Rename Comment::permalink() to not be ambiguous with ::uri()
Comment #19.0
andypostrelated #1970360-78
Comment #20
andypostComment #21
sunGiven 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:
(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:
↓
/comment/$idURI is replaced with the URI of the context.?comment=$idquery string./comment/$idis a separate and separately cached URI, too: Zero difference.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:
As a result, the most sane architecture and technical implementation I can think of is this:
Turn
Comment::permalink()into this:Make {whichever-code} that generates the permalinks for comment fields attached to other entities call this:
→ resulting in e.g.
/node/12345?comment=45678#comment-45678The real gist: Add a Request event subscriber to Comment module, which
/node/12345)->query->has('comment')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.
Comment #22
andypostThe 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
Comment #23
catchThat'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.
There's no redirect in Drupal 7, there's a menu_execute_active_handler() call, and a subrequest in 8.x.
Comment #24
mgiffordComment #27
larowlanComment #28
fil00dl commentedHere 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”.
Comment #37
andypostIS needs update cos deprecation of
comment_uri()still makes sense, not sure as it bugComment #38
andypostupdated IS
Comment #39
andypostLet's see effect of removal
Comment #40
andypostAdded deprecation, CR still needed but let's see how often it's used
Comment #44
catchUpdated the issue title, this is just a straightforward deprecation now. Needs a re-roll updating the deprecation version.
Comment #45
andypostFiled CR https://www.drupal.org/node/3384294
and updated patch, looks there's no test for
uri_callbackannotation in comment entityAlso 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
Comment #46
andypostupdated IS
Comment #47
catchComment::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?
Comment #50
samitk commentedHello,
The
comment_urifunction is only been used inuri_callbackcomment entity's annotation.As per https://www.drupal.org/project/drupal/issues/2667040 ticket the uri_callback is also depricated.
In
template_preprocess_commenthook$comment->permalink();is already been used to generate Comment link.Thanks
Samit K.
Comment #51
smustgrave commentedTitle says to deprecate the function so that still needs to be done
Comment #52
samitk commentedHi @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.
Comment #53
samitk commentedComment #54
smustgrave commentedYes but it got missed so now needs to be properly deprecated
Comment #55
samitk commentedHi @smustgrave,
Updated the code based on your suggestion. Also updated the changes record [#3384294].
Thanks
Samit K.
Comment #56
smustgrave commentedThanks only thing missing is a quick deprecation test
Comment #57
samitk commentedHi @smustgrave,,
Test also added, Please review.
Thanks
Samit K.
Comment #58
smustgrave commentedComment #59
samitk commentedComment #60
larowlanCouple of minor questions/nits on MR, thanks for keeping this moving
Comment #62
shalini_jha commentedRebased & fixed the merge conflict, looking into the MR feedback.
Comment #63
shalini_jha commentedI 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.
Comment #64
smustgrave commentedLeft another small comment on MR.
Comment #65
shalini_jha commentedI am working on it
Comment #66
shalini_jha commented@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.
Comment #67
smustgrave commentedLeft 1 more comment on the thread started by @larowlan
Comment #68
shalini_jha commentedMoving this for your review.
Comment #69
shalini_jha commentedRemoved the comment on the return statement, as I believe it was not appropriate.
Kindly review.
Comment #70
berdirThis 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...
Comment #71
shalini_jha commented@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.
Comment #72
berdirYes, 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).
Comment #73
shalini_jha commented@berdir, Thank you for the Information :)
Comment #74
smustgrave commentedBelieve all feedback for this one has been addressed.
Comment #75
quietone commentedI 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.Comment #76
berdirthe 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.
Comment #77
shalini_jha commentedAddressed 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.
Comment #78
smustgrave commented@shalini_jha big thing it was sent back for seems to be issue summary update which still appears to be needed
Comment #79
shalini_jha commentedAh yes i missed to this IS update tag , sorry for the inconvenience, i am working for this.
Comment #80
shalini_jha commentedComment #81
shalini_jha commented1 usage in contrib found http://grep.xnddx.ru/search?text=comment_uri&filename=
Removed this line as given url is not working
Comment #82
shalini_jha commentedComment #83
shalini_jha commentedI 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.
Comment #85
longwave#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
Comment #86
longwaveComment #88
catchCommitted/pushed to 11.x, thanks!