Issues with hook_comment()

theabacus - January 12, 2009 - 17:11

I am trying to adjust some comment data on comment insert/update, however, hook_comment is not working for me at all.

function custom_comment(&$a1, $op) {
switch($op) {
case "validate":
$a1['comment'] = "Testing";
break;
}
}

I know the function is running at the appropriate time and is changing the $a1 array. However, the comment text is not being saved as "Testing"...instead it is being saved as the original data the author put in. Any thoughts?

I did some more

theabacus - January 12, 2009 - 17:28

I did some more research/testing on it. As to be expected, the order of operations is hook_comment($op=validate)->comment_save()->hook_comment($op=insert).

I ran a print_r($edit); in the top of the comment_save module. It appears that even tho $a1 is being passed by reference, the comment module is not using the same array when it saves...

I have exactly the same problem

nexus666 - February 8, 2009 - 19:54

I'm a bit of a newbie, but I also find it strange that I can't seem to change the $a variable. And how do I stop the comment completely from being inserted, not only changed?

caching problem?

alberthendriks - February 9, 2009 - 17:03

I'm not sure, but perhaps you should clear the cache.

http://www.seo-expert-blog.com/blog/clearing-drupals-page-cache-after-ad...

 
 

Drupal is a registered trademark of Dries Buytaert.