While the paging links display the correct comments do not load when you try to go to a subsequent page in the comments.

Seems like this module needs a lot more testing before being ready for production usage.

Comments

sokrplare’s picture

Looks like this is due to comment_node_page_additions being called twice. Once by the comments module itself as it uses comment_node_view, the second time by commentsblock_block_view.

Now aside from slower processing, this wouldn't be an issue except...
Both functions call comment_node_page_additions, which in turn calls comment_get_thread, which - and this is the key - extends PagerDefault in it's $query object.

PagerDefault lives inside pager.inc and each time it is called, (here is where I'm a little fuzzy, so could be wrong) it registers that caller as a unique paging element on the page. Because it is called twice the pager things the second call is a second element on the page and as a result it never picks up the first element's page URL - since it is looking for a second one!

To confirm this, you can switch the URL from ?page=1 to ?page=0,1 and voila - paging "works"!

I've attached two screenshots showing the elements being picked up and the double-calls. The second time you can see in the URL I've added the second element - and that time it worked to load the second page of comments.

sokrplare’s picture

Status: Active » Needs review
StatusFileSize
new1.29 KB

Thanks to help from http://drupal.stackexchange.com/a/27406/6581 I've got a patch.

I don't think this would break anything comments-wise, but it needs testing by those who choose "Yes" to the configuration option of "Display comment form only?" and use a View to list comments.

sokrplare’s picture

A quick search just of contrib module we are using for our(large-ish) site turned up uses of hook_module_implementation_alter by:

  • entity - "Moves the hook_entity_info_alter() implementation to the bottom so it is invoked after all modules relying on the entity API. That way we ensure to run last and clear the field-info cache after the others added in their bundle information."
  • pathauto - "Adds pathauto support for core modules."
  • token - "Adds missing token support for core modules."

Not feeling like that commentsblock module is quite on the same playing field as these practically core "contrib" modules.

However, I looked at using the example shown in the API docs for hook_module_implements_alter() which is:

function hook_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'rdf_mapping') {
    // Move my_module_rdf_mapping() to the end of the list. module_implements()
    // iterates through $implementations with a foreach loop which PHP iterates
    // in the order that the items were added, so to move an item to the end of
    // the array, we remove it and then add it.
    $group = $implementations['my_module'];
    unset($implementations['my_module']);
    $implementations['my_module'] = $group;
  }
}

Trouble is, pushing comment_node_view() to last in the list of executed hooks doesn't help if hook_node_view() is being called in it's entirety before hook_block_view() which commentsblock uses.

marcoka’s picture

saw your other patches, thx for that. i will check them.
is this paging error when using views to display comments or without?
the demo uses views and that seems to work
http://drupal-demo.artwaves.de/comments-block

sokrplare’s picture

Without Views (sorry for the late reply).

marcoka’s picture

so did you find a fix so far?

sokrplare’s picture

I think the patch in #2 is the fix. We set the comment limit to 300 on our site so that we effectively never have paging.

marcoka’s picture

ok lets wait for some testers that can set it to RTBC

sokrplare’s picture

Works for me!

marcoka’s picture

i am currently not having enough time to commit stuff. if anyone wants to co maintain, tell me.

marcoka’s picture

soon the 2.x will come out, with a different approach. It may be fixed there. testing needed.

marcoka’s picture

can anyone check/confirm this with the new 2.x?

erlendoos’s picture

Version 2 has the same problem... what must I look for to fix it?

erlendoos’s picture

The comments block can also be disabled by using display suite. Maybe you should just not want to solve this in your module, but advise to use display suite for hiding the comments section, or in the template?

erlendoos’s picture

How about this:

function commentsblock_node_view_alter(&$build) {
  //comment_block_static_comments($build['#node']->nid, $build);
  $build['comments']['#_access'] = $build['comments']['#access'];
  $build['comments']['#access'] = FALSE;

And this:

        $build = node_view($node);
        $build['comments']['#access'] = $build['comments']['#_access'];

        // Allow other modules to disable the comments (you'll never know)
        drupal_alter('commentsblock_comments_access', $build['comments']['#access'], $node);

        $block['content'] = drupal_render($build['comments']);

only... pager not working.... maybe still use a view instead of native comment rendering?

erlendoos’s picture

Solved, and here is the issue + patch https://drupal.org/node/2089475