Problem/Motivation
Views could not be filtered based on a comment field's status of Open, Closed or Hidden. Views were showing every row. An example is a "hidden comments" filter that still shows all comments.
Testing steps
- Enable Comment module and add comments to a content type.
- Create a node view and add a filter on the comment field's status column. Only the numeric handler is available.
- Set the filter to one status value and save.
- Preview the view. All nodes are returned regardless of comment status.
Proposed resolution
Use a comment_status field formatter for comment fields that shows the status as an Open, Closed or Hidden label .
Remaining tasks
Create a change record for the deprecation - https://www.drupal.org/node/3628701
User interface changes
- Views UI comment fields' status filter "Comment status" available with the Open / Closed / Hidden options.
- "Comment status" formatter is available for comment fields display.
Data model changes
Update hook rewrites saved views to use to the node_comment filter.
Generated with the help of an LLM.
Comments
Comment #2
mpolishchuck commentedAdding the patch.
Comment #3
mpolishchuck commentedComment #6
kristen polNot sure if this should be considered for core, but patch applies cleanly to 9.1.x.
Comment #10
harlor commentedWell #2 breaks the current behavior of the comment field. Instead of the list of comments one only gets the comment status in views.
Can't we just add a field formatter as an alternative to CommentDefaultFormatter to show the comment status?
Comment #11
harlor commentedSorry I just uploaded an incorrect patch.
Comment #12
kristen polTagging for testing.
Comment #13
kristen polI reviewed the code and it looks very clean :)
Comment #14
joshua1234511Thank you @harlor, On reviewing the code found the below issue.
Patch being applied at incorrect location.
Should be a/core/modules/comment/src/....
Updated the patch to apply at correct path location.
Manually tested the patch, works as expected.
Comment #15
kristen polThanks @joshua1234511 for updating the patch. If someone uploads a patch, then they aren't supposed to RTBC the patch so I'm moving back to needs review so we can get other eyes. I might be able to review today.
Comment #16
kristen polTo review the code more carefully, I wanted to see how status is handle in views for other things and here's some things I found:
class Status extends InOperatorclass Status extends FilterPluginBaseclass NodeViewsData extends EntityViewsDataclass Status extends FilterPluginBaseclass UserViewsData extends EntityViewsDataIn the comment module currently, there are these filters:
NodeComment,StatisticsLastUpdated, andUserUidwhereNodeCommentis currently dealing with status:The patch adds a
FieldFormatter(CommentStatusFormatter). I don't see a similar pattern for theFile,Media, orNodeentities, so I'm not clear this approach would be accepted into core.Comment #17
kristen pol@joshua1234511 Would you please update the issue summary with steps to test this?
Comment #18
joshua1234511I updated the issue summary with testing instructions.
Comment #19
joshua1234511@mpolishchuck thinking of the use case, the patch provided adds a new field formatter, that only displays the status and not all details. As far as views are concerned a status field can be easily added to views and the filters can be obtained. the default views show only enabled comments and un approved comments are shown in another tab view.
as the status will be available only for admin, don't see its use for regular users.
and comments are already filters in
.../admin/content/comment
.../admin/content/comment/approval
Comment #20
kristen polThanks for the clarification @joshua1234511. Since the title and issue summary mentions views, I assumed that the patch would be updating the views filter or field.
Tagging for updating the issue summary to clarify what this new feature really should be.
Comment #21
kristen polMoved the testing steps higher up on issue summary so they are easier to find.
Comment #23
deepalij commentedComment #24
anchal_gupta commentedI have applied Patch #14, it was successfully applied and working fine.
Comment #25
deepalij commentedSuccessfully applied the patch #14.
Testing Steps followed:
1. Applied the patch
2. Cleared cache
3. Go to /admin/structure/types/manage/article/display
4. Ensure the Comment field options -> Select "comment status" -> Save
5. Now, create content of type Article (for checking the comment status) by visiting /node/add/article
6. Fill up mandatory fields -> Save
7. Observe the error message
8. Go to the Recent log messages and check the error
Expected Result:
Selecting and saving the settings should show the comment status for each comment
Actual Result:
Comment status is available in the manage field
But, to check the comment status on comments when trying to create a node, it's giving the 500 error message as shown in the attached video and in the screenshots
Hence, moving to needs work.
Comment #27
bobooon commented+1 RTBC for #14 on Drupal 9.5.x. Previously reported errors appear to be related to using the new Olivero theme. Not this patch.
Comment #28
smustgrave commentedWas tagged in issue summary in #20 which still needs to happen.
Comment #32
philltran commentedI submitted a MR that restores the Views integration from patch #2 on top of current main, and keeps the formatter from patch #14.
The MR now includes an update path. Saved views with a numeric filter on a comment status column are converted to the node_comment filter. Views config saved later with an old numeric filter, such as an imported pre-update export or module-provided config, is converted on save and triggers a deprecation.
Range operators ("<", "<=", ">", ">=", "between", "not between") are converted to an "in" list, because the node_comment filter ignores numeric operators and returns every row.
Generated with the help of an LLM.
Comment #33
philltran commentedUpdated summary per #20
Comment #34
philltran commentedComment #36
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 #37
philltran commentedcspell was failing on French words in the tests. The cspell tests are passing now. Ready for review.
Comment #38
smustgrave commentedKicking back purely because the summary appears to be copy/paste from AI, please see https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett... summaries need to be own words.
Comment #39
philltran commented@Smustgrave Thank you for reviewing the issue. I did condense the verbose output from the AI in my summary re-write. I have further edited the summary. Please let me know if I need to may any other changes.
Thanks!
Comment #40
philltran commented