Follow up for #731724: Convert comment settings into a field to make them work with CMI and non-node entities
Problem/Motivation
#731724: Convert comment settings into a field to make them work with CMI and non-node entities Moves comment to a field api field. We would love to get the threading and pager settings into the formatter, instead of the field settings, this would allow this to be used in views etc ie anywhere else display settings can be configured
Also the UX around field settings is poor.
Also there is lots of juggling code around view modes in the comment formatter.
Lets clean it up
Proposed resolution
Move threading and pager settings into formatter settings (from field settings).
Move comment_new_page_count and comment_num_new to the CommentManager service
Change arguments to comment_new_page_count to include passing the number-per-page and the threading mode as arguments instead of fetching them from the field.
Update formatter-output to include data-comment-per-page and data-comment-mode attributes. Send these attributes to CommentController::renderNewCommentsNodeLinks() allowing it call the comment_new_page_count function with the new arguments (note it is the only place this function is called).
Remaining tasks
- Write the patch.
- Take screenshots (show the current UI and annotate showing what will change).
User interface changes
Settings will be moved from field settings to formatter settings.
API changes
comment_new_page_count moved to manager service and new arguments.
Note CommentController::renderNewCommentsNodeLinks is the only place this function is called.
This will move settings from comment-field instance settings to one of comment-formatter or comment-type config-entity - so config schema changes
Related
Postponed on #2068331: Convert comment SQL queries to the Entity Query API and #1920046: Remove comment_entity_view and introduce second formatter for links
Comment | File | Size | Author |
---|---|---|---|
#102 | interdiff.txt | 1.57 KB | googletorp |
#102 | move_comment_field-1920044-102.patch | 87.34 KB | googletorp |
#100 | move_comment_field-1920044-98.patch | 87.55 KB | googletorp |
#98 | move_comment_field-1920044-98.patch | 87.55 KB | googletorp |
#86 | interdiff-1920044-73-86.txt | 9.05 KB | kerby70 |
Comments
Comment #1
dixon_Comment #2
andypostThis change require to unify the output generation logic so formatter simply calls a function with parameters.
Also this change affects a way we generate a link to calculate a page for another formatter (links) so this a ONLY problem here
The number of page of the comment depends on both parameters so I think the Links formatter should get settings from "full" mode formatter and fallback to defaults when full is not CommentList
Comment #3
andypostAnother task here to implement
node_title_list()
theme-override to show the comment countComment #4
podarokLooks like this workaround brokes standard drupal view modes
Possibly if this will be resolved in such way - should we provide a good docs and disabling some administration forms in core for comments?
Comment #5
andypostClosed as duplicate #1830966: Define comment_per_page_options as config
Comment #6
larowlanWorking on this one too
Comment #7
larowlanUpdated issue summary with discussions regarding CommentController::renderNewCommentsNodeLinks()
Comment #8
larowlanTagging for the changes to comment_new_page_count
Comment #8.0
larowlanUpdated issue summary.
Comment #9
Wim LeersYep,
CommentController:renderNewCommentsNodeLinks()
should then be updated to either receive the number of comments per page (meaning that they'd be stored in the client-side, meaning that a malicious user could easily try to overload the server by manipulating this number) or the formatter ID with which that setting is associated. The latter seems to be the safer option.I'd say the route's path should be updated from
path: '/comments/render_new_comments_node_links'
to:
Comment #10
larowlanBut what if views uses it as a formattter, we don't have a formatter id?
Comment #11
Wim LeersSo how does Views do it then? If Views is not using the same render pipeline, then quite possibly it should provide a similar yet different route that accepts the view ID and display ID, and retrieves the settings from there?
Comment #12
andypostNot sure I get the new idea about node-links but originally the was idea to implement second formatter to use for teaser to display links only.
Also logic to count page and query thread could be changed slightly in #2068331-30: Convert comment SQL queries to the Entity Query API
Comment #13
larowlanSo we should postpone on #2068331: Convert comment SQL queries to the Entity Query API and #1920046: Remove comment_entity_view and introduce second formatter for links then
Comment #13.0
larowlanUpdated issue summary.
Comment #13.1
larowlanuis
Comment #14
clemens.tolboomFrom what I read in #1901110-6: Improve the UX for comment bundle pages and comment field settings from one of the screenshot has a 'Allow comments link' but that's removed from that issue as #1901110-13: Improve the UX for comment bundle pages and comment field settings mentioned this issue.
Reading here I don't read about hiding the 'Add new comment' link per display mode as #2141929: Comment link or form is added to print view mode. and #1166114-107: Manage Displays Search Results doesn't manage the display of the search results.
Am I wrong or can I try to fix for only D7 #2141929: Comment link or form is added to print view mode.?
Comment #15
larowlanKicking this back off
Comment #16
larowlanInheriting priority from others marked as duplicates:
#1920046: Remove comment_entity_view and introduce second formatter for links
#1901110: Improve the UX for comment bundle pages and comment field settings
Comment #17
andypostI still think we need some kind of "inheritance" for this settings.
At least "per-page" should be inherited for formatter from field or instance or comment bundle
Comment #18
larowlanby inheritance you mean a default value?
Comment #19
andypostexactly default value
Comment #20
andypostTo properly retrieve settings from formatter within other code this code needs to provide view mode or entity display with settings for formatter.
So the only question how to pass data-* attributes from formatter to node links
Comment #21
Wim Leers#20: Can you explain what the problem is with the
data-*
attributes?Comment #22
andypostThe problem is that comment field and node links are laying in different elements.
So when comment field is displayed (currently with field and comment wrappers) then some JS needs to pull this into node links.
But comments could be attached to any entity so this kind of formatter should work everywhehe
Comment #23
Wim Leers#22: so… are you saying that
comment-new-indicator.js
andnode-new-comments-link.js
should be updated to work with entities in general and not Node entities in specific? Is that all, or is there more?Comment #24
andypostYes, both should be updated. Also code in node links should be tuned.
I just have no idea how to display this links for entities that have no "node-links"
Comment #25
catchI think node links are more the problem than the other entity types, that's Drupal 4.7 (or earlier) stuff we've never refactored.
Comment #26
xjmWe discussed this today with @Dries, @alexpott, @catch, and @webchick. This was elevated to critical because #1901110: Improve the UX for comment bundle pages and comment field settings was critical. However, we agreed this morning that while the usability issues with the current UI are pretty significant, they are not release-blocking. We also agreed that we could add an improved UI in a minor release (e.g. 8.1.0) if it is not ready for 8.0-rc1. I'm introducing a "minor version target" tag for that.
The issue summary could use an update here, especially to include the scope of the duplicate issues. @yoroy provided UX feedback with screenshots in #1901110: Improve the UX for comment bundle pages and comment field settings that should be documented and incorporated in this issue as well -- the current summary is very weak at explaining the UI changes. Let's add a screenshot at least showing the current UI and with maybe an annotation showing what will change.
Comment #27
TallDavid CreditAttribution: TallDavid commentedComment #28
larowlanPostponed on #2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form which will simplify things here
Comment #29
larowlan#2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form is in
Comment #30
larowlanClose to a patch here...
Comment #31
larowlanLets see how broken tests are.
Screenshots from manual testing.
Comment-field settings
These could probably be moved to the comment-type settings eventually.
Comment formatter summary
Comment formatter settings form
Options for links
Comment link formatter summary
Comment #32
larowlanComment #34
larowlanhmm comment_get_display_ordinal() and comment_get_display_page() going to be an issue. Called from the CommentForm submit handler...
Might need to inject the view_mode into the form when its displayed... should be doable, as form is tied to a formatter.
Comment #35
larowlanShould fix a few tests
Comment #36
Bojhan CreditAttribution: Bojhan commentedInteresting, this move makes sense. It will be a bit of a search for our existing users, but that should be fine.
1) I am not sure what "Show links" does frankly?
2) Can we remove the description for threading? We can probably just move most of that into the label.
3) We can remove the description for Show links
Comment #38
larowlanI'm no longer convinced that 'no per page' and 'threading mode' belong on formatter, but certain that links do (so they can be controlled with formatter options/disabled etc). In fact I think 'no per page' and 'subject' etc all belong on comment-type settings form now, not in field settings and only 'pager id' and 'link style' are formatter settings with no settings for field or instance at all - thoughts?
Moving those options to the comment-type is consistent with node-type etc.
Assigning to andypost for feedback.
Comment #39
larowlanThis change is why I'm not certain that they belong on the formatter. The comment-form needs to know the number per page and threading mode in order to create the link fragment after a new comment is added - to redirect to that comment. On one hand we're already assuming that the comment came from the full-entity view mode (because we're using the commented entity's url info to build the link) - is it a bridge too far to assume that implies the default view mode? Or should we remove this redirect all together and make it configurable per-comment-type? Options would be 'commented entity in default view mode', 'comment reply form' and 'none'.
Comment #40
jhodgdonThis seems like a can of worms. In order to make this permalink to the comment, you have to know how/where the comments are displayed, which is the "full" view mode setting on the entity bundle, I guess? This does seem like a formatter setting for that same type of comment?
Comment #41
larowlanSo after discussing with @jhodgdon on irc, I think the best option here is to continue with the patch approach but make the redirect location configurable. In some instances the full view mode of the entity will be correct, but we shouldn't assume that.
Thoughts on that too?
Comment #42
andypostYep, this is "pandora box" of comment field.
Each time the comment field is rendered the formatter should know the view mode.
Each comment entity render should care about user permissions to render links properly.
The comment permalink still not solved:
#2010202: Deprecate comment_uri() & #2113323: Rename Comment::permalink() to not be ambiguous with ::uri()
and each calculation needs a lot of resources.
Also comment render cache is broken now #2254181: Comment indentation is incorrect for comments following a replying-comment: don't render cache comments for which threading is enabled
And finally we are in progress to convert queries to EQ.
As we discussed this options my vision was to place:
1) threading to comment type.
2) per page and form placement to formatter.
3) pager_id was introduced as quick fix but still there, no idea how to fix that properly.
"show_links" - nice idea for formatter! just take care about render cache.
Overall +1 to current approach, will try to help.
PS: about dancing with node view modes - please try to use entity display properly, I mean to get rid of
unset()
and move comment field to "hidden"better to merge
please, fix that
suppose better to unset a whole field unset($variables['content'][$field_name]);
you get warning with NULL
Comment #43
andypostForget to point to a duplicate issue #1901110-6: Improve the UX for comment bundle pages and comment field settings my initial approach for the subject
Comment #44
andypostComment subject visibility is tricky in #2292821-7: Use widget for comment subject field
Comment #45
andypostre-roll, pushed to github
Comment #47
andypostFacing with #2324719: Node indexing - should use view mode for comments, not hook shows that we need to move per page settings to formatter to get rid of view mode check
Comment #48
jhodgdonI took a look at some of this patch... mostly looks good! At the top though, I'm not sure why there are two nearly identical blocks in function comment_modules_installed($modules) ... couldn't those two if() statements be combined?
Comment #49
larowlanWe really need to sort this before beta
Comment #50
larowlanThis will move settings from comment-field instance settings to one of comment-formatter or comment-type config-entity - to be explicit.
Still chasing feedback on #38 and #39
Comment #51
larowlanComment #52
roderikIn the process of rerolling. This patch now has duplicated code in CommentDefaultFormatter (from this issue) and CommentLinkBuilder (from 8.0.x / #2318251: Make comment links functionality testable and convert CommentLinkTest to PHPUnit) which I'll dedupe out soon -- in the meantime, the testbot can figure out whatever I messed up, overnight.
Also on github when push finishes.
Comment #54
roderikstill 'needs work' but I'm using the testbot again to see what sticks.
Duplicate code still there, I now think I should
Comment #56
catchOK the API change here is not going to affect much/anything - definitely not out of beta scope.
However I would not want to deal with the risk/complexity of having to write an upgrade path for this during beta.
So... I'm retagging as 'D8 upgrade path' / minor version target. If this gets in before we support beta-to-beta updates then I think it's an OK change to make. After that don't fancy it before release candidate.
If it misses that window, and we can get the upgrade path right and fully tested it could still get into 8.1.x (or later) as a UI improvement - but that gives us an extra six months or so to ensure the upgrade path is spot on and test it on real installs.
Comment #57
roderik(coming up)
Comment #58
larowlanHi @roderik, I'm still chasing feedback on #38 and #39, so don't sink too much time into this in case we about face. Also w.r.t. links I think it makes sense to separate the concerns now that links are a distinct display component in core. I.e. we don't need to worry about making them configurable any more, they already are in head.
Comment #59
roderikSo, it's about time I uploaded the current status. Don't worry if there's wasted work - this was useful as practice in config entities/field settings/formatters/unit tests etc. if nothing else.
Unfortunately there's a lot of stuff to split out, which I tried and only half finished.
1 - reroll
3 interdiffs:
1a is unimportant, just reroll/test fixes from last patches.
1b is a few things I thought should be fixed. (Primarily: I think the teaser vs full node links were switched - but it's a bit hard to test still)
1c unifies the duplicate code in CommentLinkBuilder and CommentDefaultFormatter - it creates a new method CommentLinkBuilder::buildCommentedEntityFieldLinks() (with arguments tuned to CommentDefaultFormatter's use case).
Status:
CommentLinkBuilderTest fails - I believe that is because of the new CommentDefaultFormatter::LINKS_NONE formatter-setting which the test does not yet account for: CommentDefaultFormatter::LINKS_NONE outputs no link but (in at least one case) the test expects an 'access denied' message.
So, the checking logic still needs to be reviewed.
2 - feedback on #38 - #41
I believe that the # of comments does belong (should stay) in the formatter settings. (I think there is a theoretically valid use case for having small/big thread pages on different display modes.)
I believe that the threading mode should indeed move to comment-type settings. Not 100% sure on it, but my feeling is mixing up threaded/non-treaded rendering of the same comments is a can of worms and we shouldn't enable regular people to do that. (Why: because if you render threaded comments as 'flat', you don't see what the parents are / what comments you're replying to - sometimes leading to creepy situations. Which would require a solution like https://www.drupal.org/project/flatcomments in core to keep lost data / frustration down.)
In other words: agreed with andypost/#41.
'form_location' also seems like a formatter setting to me. (and maybe the new 'redirect' setting? But see below.)
Attached interdiff '2' moves the threaded mode to a comment-type setting, and can be used as a basis for moving other settings over (which I haven't thought about yet).
It also moves and renames the constants from COMMENT_MODE_* to THREADING_MODE_* (the best I could come up with after not liking 'MODE_*, DISPLAY_MODE_*, LIST_MODE_*')
CommentLinkBuilderTest has not been adjusted yet (to mock comment type settings).
3 - configurable redirect location
As mentioned in #41
Attached interdiff '3' is a first stab at this.
But I should have read properly: options should be as per #39 "Options would be 'commented entity in default view mode', 'comment reply form' and 'none'.".
I implemented "to what view mode do you want to redirect", which is a silly question. What could be asked as a question (besides the above options) is "what view mode does /node/NNN actually render? I need to know just for determining the destination page on redirect". But I'm not sure that is understandable/useful.
There is another issue with the patch:
...unless you want to implement an URL (GET) parameter for the standalone form URL...
So I'm uploading the patch for completeness / as maybe a little starting point, but not sure of its use.
The full patch in this issue
... includes inderdiffs 1 and 2, not the last interdiff (3). I already know it will fail CommentLinkBuilderTest, and for the rest... I'm just keeping my fingers crossed.
Pushing to github in case someone wants to cherry-pick.
TODO
Comment #61
roderikThat code was so broken, I don't even...
Here's a new patch including everything but the redirect location (which I'll look at while test bots are picking this apart.)
Pushed to github. I can later provide any interdiffs you want (probably from 45 to the most recent one), and review my own comments.
Comment #63
roderikRegardless whether this will be (partly or fully) unused, I must not leave a mess in an issue like this.
Testing; comments will follow if it's green.
The interdiff is bigger than the patch because the comment-links stuff that was part of #45 is removed from the field formatter.
Comment #65
roderiksilly little mistake, comments still pending when green.
Comment #67
roderikfinding individual issues to fix among the failures...
Comment #69
roderik.
Comment #71
roderikgetting funny warnings at drupalPostAjaxForm() but hoping they might be local to my installation...?
Comments and github push will still follow when green.
Comment #72
roderik...so. Ignore comments #48 - #71 (except the reference below).
1 - reroll plus fixes (plus removing the links stuff that already have their own formatter)
Pushed to github because the individual interdiffs are pretty much useless (too confusing). I will split stuff up if it helps to review/push things through. (Or if you think parts of this should not go in.)
Also: will update issue summary after there is agreement on below.
2 - feedback on #38 - #42
As detailed in #59, agreed with andypost #42:
Form location also seems like a formatter setting to me **. However this has implications: when displaying a non-'full' view mode, we first need to check that view mode's formatter settings to see if comments are displayed there. If not, we must check the 'full' view mode's formatter settings to determine whether the "Add new comment" link should link to the form on the full node page (as is the default now/in D7?) or on a separate page.
This is done in interdiffs #69 + #71.
(And it has added a @todo, which is actually a @to-review, to the patch.)
And it introduces some breakage - see bottom of this comment.
3 - configurable redirect location / issues raised in #39
Maybe I'm just slow (like I was in understanding #58)... but I don't think we have a problem here anymore. Just recapping #39 to be sure:
Yes that's a bridge too far, but that is no problem. We can just go with the full mode settings. (As done in this comment's interdiff.)
There are more places (CommentLinkBuilder, CommentController::renderNewCommentsNodeLinks()) that take the settings from 'full' view mode because that is the view mode which is hardwired to the entity's URL. AFAICS that's fine.
Great. But since that's new functionality and it doesn't seem to influence the patch much, it can be a followup - right?
-----
** I think we have to either make 'form location' a formatter setting, or decide to decouple the rendering of the comment form from view modes & only display the form on the entity-url page (irrespective of view mode).
Why that reasoning?
...try this for fun: in HEAD, you can change the 'frontpage' view to display nodes in 'full' view mode. So you'll get comment forms rendered with every displayed node, and (if there are comments already) an "Add new comment" link. But that link redirects to the entity-url, instead of jumping to the form just below it!
The only way to fix that is either of above choices, I think.
This patch takes the first choice and fixes the wrong redirect.
But it (the ability to render & link to the form on any view mode) highlights some breakage. If there are multiple comment forms on the same page, each form should get their own unique #comment-form-XXX HTML id, so the "Add new comment" link can link to the right location on the page.
I'll fix that (here or in followup) when the patch gets reviewed. It won't affect many parts of the patch.
So, todo:
Comment #74
roderikreroll. See #72;
Comment #75
larowlangreeeen - review time
Comment #76
larowlanSpent about 10 minutes manually testing, couldn't fault it.
Will upload screencast and start code review next
Can you elaborate why this is needed?
So we're defaulting to 'default' here - but theoretically we could be using a 'search result indexing' view mode yeah?
I can live with this.
nitpick: extra blank line
Thanks for more documentation, not sure on the capital ED emphasis though. We should add @see for the referenced functions/methods so api.drupal.org can link.
We've copied this twice - is it worth putting into a method somewhere?
here it is again, so 3 times = ideal candidate for a method somewhere
This so feels like a product and not a framework doesn't it.
This doesn't belong in core in my opinion. None of this link stuff does. If anywhere it should be in standard, but not in comment.
Note to self: up to CommentManager
Comment #77
larowlanReview part 2 - will upload screencast tomorrow.
So yes - this works - and has tests - but at what cost - I think that some time ago (during the Drupal 7 cycle?) that comment links lost their way and attempt to solve too many use-cases, many of them specific to a particular site/product. I'm voting that we wind a lot of the comment link features back - alternate formatters can answer a lot of these question 'Same page' formatter 'Different page' formatter. We're trying to solve every use case in core - but we should only be ensuring that sites working with Drupal can solve their particular use-cases with our APIs - thoughts?
Also @roderik++ for all the effort you've put in here.
Hate to see what the cyclic complexity of CommentLinkBuilder is with this patch, it was already off the charts. Again - I think we should consider dialing back a lot of this - even splitting it into contrib. Are these links really the 90% use-case? (nothing to do with this patch, other than it gets worse to deal with here)
Why is the save() call added? Can't we do this in the original creation/default config?
yep, another time, def time to put this somewhere
And again. Can we load multiple instead of load and then use reset() - would that make it simpler?
Perhaps we put the juggling of formatter options, field definitions etc in a method on the CommentType? Just talking out loud here.
This makes it clear how complex the link building is - anyone else agree it should get dropped/split into contrib?
Yeah this definitely should just go in the default config yml that provides that view mode.
I like this.
Comment #78
larowlanTo answer the cyclic-complexity - CommentLinkBuilderTest has 2020 combinations.
Yes two thousand and twenty that is not a typo.
Yeah it only takes 1.35 minutes to run because its decoupled and php unit but c'mon - comment module is doing too much - especially as this functionality is only used for nodes.
CRAP index is 37.5
Cyclic complexity is 37 (similar because we have good coverage).
Here's the code-coverage to verify we have most of it with this patch
Comment #79
larowlanComment module, we need to talk
Comment #80
larowlanSorry to go off topic about links - have spoken with @alexpott and will open an issue to propose removing a lot of that logic
http://youtu.be/mj00GpaU52Y is the url to the manual testing screencast
Comment #81
larowlanActually this patch makes it worse - on HEAD
The method buildCommentedEntityLinks() has a Cyclomatic Complexity of 27.
The method buildCommentedEntityLinks() has an NPath complexity of 1204.
So its bad in HEAD, but worse with this patch.
Comment #82
larowlanAlso the phpunit combinations go from 580 in HEAD to 2020 here.
Comment #83
larowlanOpened #2377849: Simplify what CommentLinkBuilder is doing - consider removing a lot of the functionality
Comment #84
jhodgdonShould we postpone this issue on the "reduce complexity" issue then?
Comment #85
idebr CreditAttribution: idebr commentedWas going to give this a manual test, but it no longer applies :<
Comment #86
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedAttached is as much of a reroll as I could get through. A few method calls look like they have moved so it still needs work.
I did not find the right place for these changes.
Comment #87
andypostI'm sure we need to postpone that to find a way to investigate #81 and only then continue here,
#1548204: Remove user signature and move it to contrib and #2428509: Comment links weight should be managed by view display will simplify render also there's special #2002094: Improve performance of comment.html.twig that could be converted to meta
Comment #88
mgiffordJust unassigning issues that haven't been developed for a bit in the D8 queue.
Comment #89
googletorp CreditAttribution: googletorp as a volunteer commentedComment #91
jhodgdonrestoring tag
Comment #92
googletorp CreditAttribution: googletorp as a volunteer commentedAh sorry, didn't notice the rerolled patch needed rerolling.
Tried to do my best to reroll this, a lot of things has changed, but this can give us a starting point.
Comment #94
googletorp CreditAttribution: googletorp as a volunteer commentedFixed merge issue from reroll in #92.
Comment #96
googletorp CreditAttribution: googletorp as a volunteer commentedIf at first you don't succeed :(
Comment #98
googletorp CreditAttribution: googletorp as a volunteer commentedComment #99
googletorp CreditAttribution: googletorp as a volunteer commentedComment #100
googletorp CreditAttribution: googletorp as a volunteer commentedTrying to reload file to get it tested, something seems a bit of with test bot not testing patch form #98
Comment #102
googletorp CreditAttribution: googletorp as a volunteer commentedReduced a lot of the fails.
Got some issues with $node->rss_elements not sure if the issue is the test or the code.
Comment #104
larowlanGiven #2559833: Comment form should redirect to the current page when the form is in a block I think we actually might need to make the redirect path configurable
Comment #105
xjmThis issue was marked as a beta target for the 8.0.x beta, but is not applicable as an 8.1.x beta target, so untagging.
This could potentially be implemented in a minor with BC, so moving to 8.2.x.
Comment #118
quietone CreditAttribution: quietone at PreviousNext commentedUpdating tag.