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

dgtlmoon - January 25, 2008 - 03:37

Attached patch to work around this (just add a reference to $comment)

AttachmentSize
hook_comment.patch 379 bytes

#2

opensanta - May 8, 2009 - 21:22
Version:5.x-1.x-dev» 6.x-1.0-beta1
Status:active» fixed

This is fixed in the latest release.

#3

System Message - May 22, 2009 - 21:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.