Is there a way to prevent/override hook_node_view from firing?

Events happening in the community are now at Drupal community events on www.drupal.org.
sokrplare's picture

I need to use the Commentsblock module, but it is turning out to be pretty buggy. I've got an issue in the queue with a patch for comments not displaying for anonymous users.

Now I've got a second issue posted about how paging is broken, but I'm stumped on how to fix it so wanted to see if anyone else had an idea.

Here is the issue: http://drupal.org/node/1513910

My question is: Is there a way to prevent the comment_node_view function from executing?

Or....should I be going about this an entirely different way (backup plan is to use Views to display comments in a block, but I can't think of a way to respect threading so would like to avoid that if possible).

Comments

I don't know exactly what you

mtbosworth's picture

I don't know exactly what you are going for but trying to block comment_node_view is going to some side affects (its part of core). I would create a new node.tpl.php file for your content type. There you can hide the default comment view and use views_embed_view if you want to use views to control how the comments are displayed.

Mike Bosworth
Balanced Scale Media, LLC
balancedscale.com

Pager still gets called

sokrplare's picture

Hmmm...good idea, however I believe comment_node_view will still get called even with a different node.tpl.php file. As it is, the commentsblock module is already unsetting the comments view:

<?php
function commentsblock_node_view($node, $view_mode, $langcode) {

 
// unset node comments because we render them in our block
 
unset($node->content['comments']);
  ...
?>

However, that doesn't prevent it from running and causing the pager issue.

It looks like there might be a solution using hook_module_implementation_alter(). I'll give it a shot and report back!

Fix working!

sokrplare's picture

Thanks to http://drupal.stackexchange.com/a/27406/6581 I've got a patch put in place that seems to work using hook_module_implementation_alter() like so:

<?php
function commentsblock_module_implements_alter(&$implementations, $hook) {
  if (
$hook == 'node_view') {
    unset(
$implementations['comment']);
  }
}
?>

Now the only question is what you alluded to, Mike, is unsetting a function in a core module such a good idea? Maybe necessary for this, but I'm concerned about any unintended consequences...

sokrplare's picture

A quick search just of contrib module we are using for this (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.

Central Iowa Drupal Users Group

Group categories

Category

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: