Needs work
Project:
Drupal core
Version:
main
Component:
comment.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Sep 2013 at 21:34 UTC
Updated:
3 Jan 2026 at 20:07 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tancSimple patch which replaces the node table with node_field_data table to fix the last updated/commented field. The handler for the filter and sort seems to be broken so I couldn't test, will check if there is a separate issue for that.
Let me know if this covers this issue, maybe there are other things I've missed.
Comment #3
andypostre-roll, seems needs tests
Comment #4
andypostNew patch:
- "ces" plugns now detects data table of the entity
- added demo view against User entity, to properly check that plugins work with other entities
- filed issue #2380071: No way to add comment field to any entity - you need to create a new comment type to add comment field to other entity
When commented entity has "changed" field then filter should use
addWhereExpression()no idea how proceed with that.I'm using
$this->options['relationship']to get entity type, is that right?Comment #5
andypostAdded test and changed view to use node
PS: test is broken somehow
Comment #7
andypostpatch with debug, and fix from #2322457: Error in Views Filter Nodes based on Current user that have term reference same in nodes.
Comment #9
dawehnerJust a quick review ...
We don't necessarily have to do that, we could also just add that handler manually to the corresponding field in
hook_views_data()WIth the technical from above we could just leverage 'real field' here
Nope, it constructs a different kind of object.
Comment #12
pcambraPlain reroll
Comment #14
pcambraA couple of small fixes, not sure what's the change proposed in #9. Shall we do something like this in CommentViewsData:
And get rid of StatisticsLastUpdated?
Comment #16
andypostsure, makes sense and simplifies a code.
But I stuck with expression that inherited from date plugin #4 (see debug #7)
Comment #17
andypostComment #18
gaydabura commentedComment #21
just_like_good_vibeshello,
any update on that issue?
i have Drupal 8.2.2 and I created a view that simply list the Article content type, ordered by "Updated/commented date".
But unfortunately, i'm unable i got the following error :
Column not found: 1054 Unknown column 'node.changed' in 'field list':
the code that creates this error is probably in the file core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
the SQL query created includes something like "GREATEST(node.changed, comment_entity_statistics.last_comment_timestamp) AS comment_entity_statistics_last_updated"
instead of "GREATEST(node_field_data.changed, comment_entity_statistics.last_comment_timestamp) AS comment_entity_statistics_last_updated"
which would be correct.
any help/explanation appreciated,
best
Comment #22
morenstratThe field handler was fixed in #2429447: Use data table as views base table, if available., though with a different approach. I attached an updated patch that applies against the 8.4.x-dev branch.
Comment #23
andypostRun tests
Comment #25
morenstratThe handler's entity type is not in $this->options['relationship'] anymore. This patch - instead - uses $this->getEntityType() to find out which entity type it relates to. Additionally, the patch replaces the deprecated EntityManager with EntityTypeManager.
Comment #26
morenstratComment #28
@rami commentedI am using Drupal 8.2.4
Is there a way to solve this issue temporary?
thanks
Comment #29
jonathanshaw@just_like_good_vibes #21 has its own issue #2841379: Unknown column 'node.changed' in 'field list' when sorting by updated/commented date.
Maybe it's related.
Comment #30
andypostClosed it because duplicates this issue
remove
should be removed
Comment #32
jonathanshaw#2879923: Unknown column 'node.changed' on filter by "Updated/commented date" has a one line fix for the node filter part of this, should probably be closed as a duplicate of this.
Comment #33
jonathanshawNovice work to address #30
Comment #34
dinesh18 commentedHere is an updated patch and interdiff implemented as per #30
Comment #36
jonathanshawThis filter has been broken for 2 years, but seems to only need a one line fix to get it working for nodes.
How about we reopen #2879923: Unknown column 'node.changed' on filter by "Updated/commented date" , move across a test from this patch, and retitle this issue as "Refactor Comment entity statistics".
Currently this issue is stuck on firstly
#4 / #16:
Can you explain more @andypost what the problem is here?
and secondly
#9 add a handler manually to the corresponding field in hook_views_data(), and then use 'real field' in the filter.
Comment #37
cellar door commented@jonathanshaw - I wholly agree! I ran into this issue and found #2879923 which seems to fix the issue, and a simple one line fix for an issue that's been around for years should make its way out, allowing more work on the re-write to occur but allowing the community to not run into the issue.
Happy to help move out the simple fix in the meantime as I'm sure there are a number of people who could use the filter.
Comment #39
dillix commented@jonathanshaw, @Cellar Door I think that this issue should be fixed for all entity types, because any entity type can use comment field.
Comment #40
dillix commented#34 works great for me should we reroll it for 8.6?
Comment #41
jonathanshawlet's see
Comment #42
dillix commentedWe should go green with testbot to review.
Comment #44
andypostIt still needs work to place test in phpunit, cos this nase class deprecated
Comment #45
webflo commentedI wrote a new test based on phpunit, works fine so far. But the filter handler fo the views has some issue with config schema. I was not able to save the view if this filter is present.
Comment #47
webflo commentedComment #48
jonathanshaw@webflo given the earlier comments on this issue, what work do you think is still needed?
Comment #50
Christie Alcidor commentedComment #52
johne commentedI just tested #47 and it worked well for nodes with comments in D8.8
Comment #53
shimpyI have tested #47 in drupal8.9
It works well.
Comment #54
shimpyComment #55
borisson_@shimpy: Please don't add a screenshot that the patch applies, this does not add any information to the system, if the patch wouldn't apply anymore then the testbot will let us know when it's being retested. in #48 there was a question to @webflo about what extra steps are still needed here.
I don't see any new replies from him - but I don't see what else should be needed.
About the actual patch.
The proper column name here is something I'm not sure about. Are we sure that this is always
changed?Same here.
We should fix this as well.
^
Can be {@inheritdoc}
Comment #56
vsujeetkumar commentedI have reviewed the comments given in #55 and According to me column name 'changed' should be fine also sql function 'GREATEST()' is working perfect in this patch.
Patch created, Please review.
Comment #57
andypost@vsujeetkumar please provide interdiff from latest patch #47
It will be easy to see what's changed
Comment #58
vsujeetkumar commentedUpdated Patch after fixed the PHPLintFailed #56
Comment #59
vsujeetkumar commentedAs I mentioned on the #56, I have just worked on comment given by #55, interdiff added Please reivew.
Comment #60
vsujeetkumar commentedPlease review.
Comment #62
vsujeetkumar commentedMore Test Fixes, Please reivew.
Comment #64
gribnif commented#62 works for me. Please test further so that this can finally be committed.
Comment #65
jonathanshawNice work @vsujeetkumar!
#55.1 is right to be concerned about this, as the @todo suggests.
The fact that an entity implements EntityChangedInterface does not guarantee it has a field called 'changed'. In fact, we can't even be sure that a field called 'changed' is a timestamp indicating when the entity was last updated, even if the entity also implements EntityChangedInterface.
I think the best solution is to require the entity to implement EntityChangedInterface, and also to check that the entity type actually has a 'changed' field. I've no idea how to do that.
Comment #66
jonathanshaw#2209971: Automatically provide a changed field definition is the issue where one day EntityChangedTrait will standardise the field to be called 'changed', but even then EntityChangedInterface won't guarantee it.
Comment #67
andypostAdded link for todo according #67
Cleaned-up constructors but as previous patch did not fail it means we missing test coverage,
that's because
\Drupal\comment\Plugin\views\field\StatisticsLastUpdatedextendsDateplugin which require "date_format" stotage in constructorit missing "date_format" storage handler
Comment #68
andypostFix CS
Comment #69
jonathanshaw@andypost do you know a way we can check for the existence of the changed field before adding it?
Comment #70
andypost@jonathanshaw
\Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalljonathanshawedDefinition()could help here, tryingComment #71
andypostKind of it works for me
Comment #72
jonathanshawNice, so glad you're working on this.
Should be 'entity' not 'node'.
This will appear to work like it is supposed to, but actually silently be unaware of the changed time, if the entity does not implement EntityChangedInterface. Is this OK?
Should we wrap this in a conditional so that this handler is only added if there is a changed field?
Comment #74
mrpauldriver commentedThank you for working on this. I am no longer seeing any errors.
Be good to see it wrapped up.
Comment #77
catchThis is a PHP error via normal site operation, so bumping priority.
Comment #78
dillix commented#34 work as expected, but with #71 I got errors for custom entity with comment field:
Comment #80
larowlanMarked related issue as duplicate, transferring credit
Comment #82
dillix commentedI applied patch #71 on latest version of Drupal and all worked fine.
Comment #83
catchTests are failing and this hasn't been tested against 10.1.x, there are also outstanding review issues from #72, so not RTBC.
Comment #84
ravi.shankar commentedAddressed point 1 of comment #72.
Comment #85
anchal_gupta commentedRerolled patched against #84. please review it
Comment #86
jonathanshawThe test fail is simple: $modules needs to be protected in CommentStatisticsTest.
#72.3 is not fixable in any way I know.
#72.2 is I think OK as is; #72.3 would solve it nicely if that were possible.
Therefore this is RTBC once tests pass on 9.5 and 10.1.
Comment #87
ameymudras commentedSmall change to fix the tests
Comment #88
lendudeNitpicks, if others think it is fine like this, don't care too strongly. Just wanted to queue up the other databases since this is doing a little more than plain queries.
Not a fan of this pattern inside Drupal core. It's great for using outside core to avoid breaks, but don't think we should do that inside core, just use Dependency Injection properly. Also, if you do this, it should add a setter so you could actually unit test this properly (which isn't possible now)
I think we try to avoid adding uuid's even in test config
Comment #89
ravi.shankar commentedI've tried to address point number 1 and 2 of comment #88.
Comment #90
lendudeThanks @ravi.shankar, same goes for the other create method being modified here, I think that should use normal DI too.
The fails on PostGres and SQLite seem unrelated.
Comment #92
ravi.shankar commentedUsed proper dependency injection in remaining classes as well.
Comment #93
ravi.shankar commentedForgot to fix the failed test of patch 89 in patch #92 so added a new patch with test fix.
Comment #96
jonathanshawThe test fail is caused by a missing use statement.
Comment #97
ravi.shankar commentedFixing failed tests of patch #93.
Comment #99
sachbearbeiter commentedWill there be a solution in the 9.5.x version? We urgently need this functionality. Or is there a solid workaround?
Comment #100
klemendev commentedDon't think there is a solid workaround there
Comment #101
sachbearbeiter commented@klemendev - thanks!
Comment #103
darvanenThe __construct method on the parent object (\Drupal\views\Plugin\views\field\Date) is expecting two more injected services:
Comment #104
darvanenAs a bugfix I'm pretty sure this should still be targetting 9.5.x.
Comment #105
ravi.shankar commentedAdded description for $date_formatter parameter.
Comment #106
darvanenAh rats, thanks Ravi :)
Comment #108
dillix commented@ravi.shankar I reviewed you patch, you need to fix translated text in views:
Comment #109
jonathanshawOtherwise RTBC I think
Comment #110
sachbearbeiter commented@darvanen @ravi.shankar Thanks a lot!
Comment #111
capysara commentedRemoved translated text per comment in #108
Comment #112
capysara commentedComment #113
smustgrave commentedThis will have to be committed to 11.x first.
Comment #114
sachbearbeiter commenteddawehner already has a long beard ... 10 years ...
Comment #115
mrinalini9 commentedRerolled patch #111 for 11.x branch, please review it.
Thanks!
Comment #117
sachbearbeiter commentedCan we pay someone to finally commit the thing?
Comment #118
jonathanshawYou could RTBC it ...
Comment #119
capysara commentedComment #123
capysara commentedI moved this into a MR instead of a patch. I'm attaching an interdiff, but I only changed the $field_alias property to allow it to be nullable to address the failed test.
Update note: I also the deleted the orig file that I unintentionally introduced in my previous patch.
Comment #124
jonathanshaw#115 introduced a schema.orig file I'm not familiar with. Is that correct? Otherwise I'd RTBC it.
Comment #125
capysara commentedOoops. That was unintentional. Thanks for catching!
I updated the MR to remove it.
Comment #126
smustgrave commentedFew nitpicky stuff.
Comment #127
capysara commentedUpdated per MR comments. Thanks Stephen!
Comment #128
capysara commentedComment #129
smustgrave commentedHiding all patches for clarity.
Ran the test-only feature
Applying locally on a standard install and doesn't appear to have issues.
Created a test view with the Comment Statistics: Updated/commented date field added, no issues
Created some test Articles adding comments as I went.
Date seems correct to me.
Comment #130
larowlanIssue credits
Comment #131
larowlanLeft some comments on the MR
Some regarding new coding standards, but also some about making sure the field-type is what we expect and some missing test coverage.
I'm keeping a close eye on this one as I'm keen to see it resolved too.
Comment #132
capysara commentedComment #133
jonathanshawFor anyone following, this is still NW for the test coverage.
Comment #134
capysara commentedStill needs tests, but I'm un-assigning myself for now.
Comment #136
capysara commentedComment #142
kasey_mk commentedI'm having trouble parsing the status of this issue and getting a working patch out of it. Unknown column 'node.changed' on filter by 'Updated/commented date' has been closed as a duplicate in favor of this issue, but it did have a patch that (with a little tweak as I commented) seems to get my 10.3.7 site back to working without errors. Sharing here in case it helps others.
Comment #143
pandepoulus commentedHello, not sure if i should comment here or create a new issue. None of the patches work for me, (i'm using the sort StatisticsLastUpdated handler).
blame is on the field_alias parameter, which is non nullable, and $this->query->addOrderBy(.....) is being called.
That function does return null, so the non nullable parameter raises an exception.
For me the solution was as easy as just call the orderBy without assigning it to a field_alias parameter, which i think is unnecesary in a sort filter.
Comment #145
alexpott@pandepoulus yep assigning the return $this->query->orderBy() to a property is pointless. I've updated the MR to fix this for 11.x.
We still need to add test coverage for the comments on entity types that do not implement EntityChangedInterface
Comment #146
alexpottSo I think we only need the StatisticsLastUpdated field, filter and sort to entity types which implement EntityChangedInterface and have a changed field. That way we avoid quite a few issues. If you want to filter on the last_updated time in comment_entity_statistics then you can use the last comment timestamp field, filter and sort... you do not need this special implementation.
Comment #147
joelpittetThis is looking good. Due to the changes not applying in D10, it’s trickier for me to test manually right now.
I’ve postponed #3540867: Views 'last updated/commented' field fails to sort entities without comment statistics on this, it’s related but not the same issue, just commenting for awareness. It's related to the stats not being populated in D8+
Comment #148
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #149
joelpittetGot the tests for
entity_testwhich doesn't implementEntityChangedInterface. I hope that gets this further. Removing the tag I added earlier.Comment #150
joelpittetForgot to change to needs review after adding the tests and attempt to shore this up by moving the logic onto the plugins.
Comment #151
joelpittetCaught up the commits, tests were passing a few weeks ago... 🤞
Any brave souls up for reviewing this so we can get this major out the door?
Comment #152
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.