Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For myself, this is a handy feature to have, so I added it to my module. I did this by adding the following code to comment.views.inc where comment pid is defined:
$data['comments']['pid'] = array(
... snipped ...
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
... snipped ...
);
Comments
Comment #1
dawehnerIt currently works fine if you use relationships.
It makes sense for me to let users use the relationships because they are a very very powerful system if you get into it.
Comment #2
iamjon CreditAttribution: iamjon commentedChanging status based on comment #1
Comment #3
v_lak CreditAttribution: v_lak commentedHi
Using relationship and enabling 'Parent CID' does help, but not fully. It works in the case when one selects the Comment ID (cid) in the filter and sets a value '!= 0' - this will fetch comments which have parents (ie., pid != 0). But to locate 'parent-less comments', ie., all comments that have 'pid = 0', the query always returns an empty result.
I believe it is due to the inner join in the query as below:
....
LEFT JOIN comments comments_comments ON comments.pid = comments_comments.cid
.... WHERE (comments_comments.cid = 0) ....
with cid = 0, no rows are fetched from comments_comments and this results in the empty resultset output of the view.
Can you please review this ?
Thanks
Venkat
Comment #4
dawehnerReview means that there is a patch.
DId you set required in the relationship?
Comment #5
hellomobe CreditAttribution: hellomobe commentedSame issue.
With parent comment relationship (required), and nothing in filter => only shows children comments
With parent comment relationship (required), and "(parent)comment id" in filter => no results
I think #3 is right that the join is throwing it off, rather than comparing within the same table (views is treating it as two tables).
A hack, is to use a global php filter:
Comment #6
jaimealsilva CreditAttribution: jaimealsilva commentedI solve it this way:
Comment #7
AnybodyI'll move that request to Drupal 8 because this is in deed very limiting if you are using views to replace the default comment display and the hook_views_data definition is also part of the Drupal 8 views, see:
http://drupalcontrib.org/api/drupal/drupal!core!modules!comment!comment....
This request could be fixed quite easily by providing the pid as filter, argument and even sort and let the developer decide how to use it. It's just some lines of code.
Simply change:
to
That's it.
In our case I needed this as filter to check "IS NULL" / "IS NOT NULL" and only output parent / child comments. Furthermore I use https://www.drupal.org/project/views_field_view to create a tree of comments of subcomments. For that I needed the pid as argument.
This flexible behaviour is not possible without the pid exposed to views.
I'll create a sandbox module (and post it here) to add it via hook_views_data_alter(). You may use it as reference.
In Drupal 8 this could be solved cleanly and be backported to older versions.
Thanks a lot for your time and consideration.
Comment #8
AnybodyHere's the sandbox module as quick solution for Drupal 7:
https://www.drupal.org/sandbox/anybody/2415813
Comment #9
LendudeMoving to the right queue.
No idea if this might be covered by #1986606: Convert the comments administration screen to a view or some of the related issues there, but could be. Checked the code, and this is currently not yet in D8 core.
Comment #25
LendudeTentatively closing this as "won't fix". There is a contrib sandbox, it doesn't seem to have a lot of uses, so I feel that we shouldn't add this to core.
Feel free to reopen this if you still think this is something we need to support in core.
Thanks.