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:

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:


  $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


  $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

Lendude’s picture

Title: Can you please add Comment Parent CID as a filter » Can you please add Comment Parent CID as a Views filter
Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.1.x-dev
Component: comment data » views.module

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

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Lendude’s picture

Status: Active » Closed (won't fix)
Issue tags: +ddd2023

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