Incompatibily with latest drupal 5.x version (hook_comment fail)
dgtlmoon - January 25, 2008 - 03:34
| Project: | Comment CCK |
| Version: | 6.x-1.0-beta1 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
comment_invoke_comment($comment, 'view'); does not use the return value as it's just a trigger for some reason to let other modules know what is going, you must declare your hook as using the $comment as a reference (&$comment) i think this is a bug in drupal-5 comment.module
function theme_comment_view($comment, $links = array(), $visible = 1) {
static $first_new = TRUE;
$output = '';
$comment->new = node_mark($comment->nid, $comment->timestamp);
if ($first_new && $comment->new != MARK_READ) {
// Assign the anchor only for the first new comment. This avoids duplicate
// id attributes on a page.
$first_new = FALSE;
$output .= "<a id=\"new\"></a>\n";
}
$output .= "<a id=\"comment-$comment->cid\"></a>\n";
// Switch to folded/unfolded view of the comment
if ($visible) {
$comment->comment = check_markup($comment->comment, $comment->format, FALSE);
// Comment API hook
comment_invoke_comment($comment, 'view');
$output .= theme('comment', $comment, $links);
}
else {
$output .= theme('comment_folded', $comment);
}
return $output;
}additionally the comment.module hands you an object but expects you to return an array of changes, but these changes (like i mention above) are never processed back into the comment output unless you modify the object in the reference (so whats the point of being asked to return an array?)
/**
* Invoke a hook_comment() operation in all modules.
*
* @param &$comment
* A comment object.
* @param $op
* A string containing the name of the comment operation.
* @return
* The returned value of the invoked hooks.
*/
function comment_invoke_comment(&$comment, $op) {
$return = array();
foreach (module_implements('comment') as $name) {
$function = $name .'_comment';
$result = $function($comment, $op);
if (isset($result) && is_array($result)) {
$return = array_merge($return, $result);
}
else if (isset($result)) {
$return[] = $result;
}
}
return $return;
}i've filed a bug against the drupal-5.x comment.module here http://drupal.org/node/214003

#1
Attached patch to work around this (just add a reference to $comment)
#2
This is fixed in the latest release.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.