In views showing comments there is no opportunity to provide a link of a single content that links to the correct page of a node's comments' list when paging of comments is activated(e.g. node/22?page=2#comment-1002).

So I did some work in views_comment.inc to solve this problem:

$tables['comments'] -> fields -> subject @ line 21

'fields' => array(
      'subject' => array(
        'name' => t('Comment: Subject'),
+       'query_handler' => 'views_query_handler_field_comentlink',
        'handler' => array(
          'views_handler_field_commentlink'           => t('Normal'),
          'views_handler_field_commentlink_with_mark' => t('With updated mark')
          ),
        'option' => array(
           '#type' => 'select',
           '#options' => array(
             'link' => 'As link',
             'nolink' => 'Without link'
            ),
        ),
        'addlfields' => array('cid'),
        'sortable' => TRUE,
      ),

Views output handler for link (@line 234)

/*
 * Format a field as a link to a comment.
 */
function views_handler_field_commentlink($fieldinfo, $fielddata, $value, $data) {
  if ($fielddata['options'] == 'nolink') {
    return check_plain($value);
  }
-  return l($value, "node/$data->nid", NULL, NULL, "comment-$data->comments_cid");
+  return l($value, "node/$data->nid", NULL, "page=".floor($data->comments_commentnum / _comment_get_display_setting('comments_per_page')), "comment-$data->comments_cid");
}

and views output handler for link with mark (@line 256)

/*
 * Format a field as a link to a 'mark', stating whether or not the comment has
 * updated since it was last viewed by the user.
 */
function views_handler_field_commentlink_with_mark($fieldinfo, $fielddata, $value, $data) {
  if ($fielddata['options'] == 'nolink') {
    $link = check_plain($value);
  }
  else {
-   $link = l($value, "node/$data->nid", NULL, NULL, "comment-$data->comments_cid");    
+  $link = l($value, "node/$data->nid", NULL, "page=".floor($data->comments_commentnum / _comment_get_display_setting('comments_per_page')), "comment-$data->comments_cid");
  }
  return $link .' '. theme('mark', node_mark($data->nid, $data->comments_timestamp));
}

and finally add a new query handler to the end of the file:
this is only for COMMENT_ORDER_OLDEST_FIRST & COMMENT_MODE_FLAT_EXPANDED at the moment

//note: only for chronologically ascending order
function views_query_handler_field_comentlink($field, $fieldinfo, &$query) {
	$query->add_table('comments',false,1,array('left' => array(
        'table' => 'node',
        'field' => 'nid'
      ),
      'right' => array(
        'field' => 'nid'
      ),
      'extra' => array(
        'timestamp <= comments.timestamp' => NULL,
      ),
    )
    );
  $query->add_groupby('comments.cid');
  $query->add_field('COUNT(comments2.cid)', '', $field['tablename'] . '_commentnum');
}

Comments

merlinofchaos’s picture

This is useful; it would be very helpful if you could upload this as a proper patch?

If you've made your modifications against a cvs checkout, making a patch is as simple as: cvs diff -up > patchname.patch

derhasi’s picture

I did some work on the views_query_handler_field_comentlink(), but don't have opportunity to test it at the moment:

function views_query_handler_field_comentlink($field, $fieldinfo, &$query) {
	$op = (_comment_get_display_setting('sort') == COMMENT_ORDER_OLDEST_FIRST)?"<=":">=";
	$fname = (_comment_get_display_setting('mode') < 3)?"cid":"thread";
	
	
	$query->add_table('comments',false,1,array('left' => array(
        'table' => 'node',
        'field' => 'nid'
      ),
      'right' => array(
        'field' => 'nid'
      ),
      'extra' => array(
        "$fname $op comments.$fname" => NULL,
      ),
    )
    );
  $query->add_groupby('comments.cid');
  $query->add_field('COUNT(comments2.cid)', '', $field['tablename'] . '_commentnum');
}

If I get into CVS I try to do a Patch-File. But i can't promise.

Besides there's still some work needed, e.g. to provide some link for Last Comment Link or First new comment link. Merily paging was fully ignored in comment.module, and so did views. But due to great $query handling functions in views, it's much easier to change it here, than in comment.module.

If I get some more time for working on this, i hope to fix it. If anyone wants to help, you're welcome!

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new16.67 KB

I did some more work on this issue:

*rewrote views_query_handler_field_commentlink(): Now it supports all comment list views
*Added new field: Comment: Custom Title to provide a field for custom titled comment links
*Added new filter: Comment: Special Comment to filter for 'new comment', 'last comment' and 'no comment'

I attached the complete views_comment.inc (previous Version: v 1.4.4.8). I try to run cvs for creating a patch file tomorrow.

derhasi’s picture

StatusFileSize
new7.52 KB

I finally got it to create a .patch-file, i attached!

edit: now upload worked. Could anyone delete my fracky last comments please ;)

derhasi’s picture

Version: 5.x-1.x-dev » 5.x-1.6
Component: Views Data » comment data

same patch, created with eclipse cvs diff

derhasi’s picture

sun’s picture

Status: Needs review » Needs work

This patch violates a bunch of http://drupal.org/coding-standards. Also, please remove the additional fields from this patch, so we just fix Comment: Link in this issue.

Oleksa-1’s picture

Version: 5.x-1.6 » 6.x-2.x-dev

Here http://drupal.org/node/26966 there is more info what is going on with this bug in core.
Any plans to port this patch to D6 ?

dawehner’s picture

Version: 6.x-2.x-dev » 5.x-1.x-dev

I think the issue should keep in 5.x

esmerel’s picture

Status: Needs work » Closed (won't fix)

At this time, only security fixes will be made to the 5.x version of Views.

jcisio’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev
Status: Closed (won't fix) » Active

Then jump to 6.x to see if it has a chance. Pager calculation is more complex than it appears. See #26966: Fix comment links when paging is used.

merlinofchaos’s picture

Status: Active » Closed (duplicate)

Comment links in D6 should already be correct. There's been several issues about this, no need to upgrade a D5 issue into the mix.

jcisio’s picture