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

dawehner’s picture

It 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.

iamjon’s picture

Status:Active» Closed (works as designed)

Changing status based on comment #1

v_lak’s picture

Version:6.x-2.11» 6.x-2.14
Status:Closed (works as designed)» Needs review

Hi

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

dawehner’s picture

Status:Needs review» Active

Review means that there is a patch.

DId you set required in the relationship?

hellomobe’s picture

Same 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:

<?php
if ($row->pid != 0){
return
TRUE;
};
?>
jaimealsilva’s picture

I solve it this way:

  1. Put parent ID on the fields and hide it.
  2. On the filters add "Global: Combine fields filter" and select only de PID field and condition: equals 0
Anybody’s picture

Version:6.x-2.14» 8.x-3.x-dev
Issue summary:View changes

I'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:

<?php
  $data
['comment']['pid'] = array(
   
'title' => t('Parent CID'),
   
'help' => t('The Comment ID of the parent comment.'),
   
'field' => array(
     
'id' => 'standard',
    ),
   
'relationship' => array(
     
'title' => t('Parent comment'),
     
'help' => t('The parent comment.'),
     
'base' => 'comment',
     
'base field' => 'cid',
     
'id' => 'standard',
     
'label' => t('Parent comment'),
    ),
  );
?>

to

<?php
  $data
['comment']['pid'] = array(
   
'title' => t('Parent CID'),
   
'help' => t('The Comment ID of the parent comment.'),
   
'field' => array(
     
'id' => 'standard',
    ),
   
'relationship' => array(
     
'title' => t('Parent comment'),
     
'help' => t('The parent comment.'),
     
'base' => 'comment',
     
'base field' => 'cid',
     
'id' => 'standard',
     
'label' => t('Parent comment'),
    ),
   
'filter' => array(
     
'id' => 'numeric',
    ),
   
'argument' => array(
     
'id' => 'numeric',
    ),
   
'sort' => array(
     
'id' => 'standard',
    ),
  );
?>

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.

Anybody’s picture

Here's the sandbox module as quick solution for Drupal 7:
https://www.drupal.org/sandbox/anybody/2415813