hook_comment

5 core.php hook_comment(&$a1, $op)
6 core.php hook_comment(&$a1, $op)

Respond to comment actions.

This hook allows modules to extend the comments system by responding when certain actions take place.

Parameters

$a1: Argument; meaning is dependent on the action being performed.

  • For "validate", "update", and "insert": an array of form values submitted by the user.
  • For all other operations, the comment the action is being performed on.

$op: The action being performed. Possible values:

  • "insert": The comment is being inserted.
  • "update": The comment is being updated.
  • "view": The comment is being viewed. This hook can be used to add additional data to the comment before theming.
  • "validate": The user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check the comment. Errors should be set with form_set_error().
  • "publish": The comment is being published by the moderator.
  • "unpublish": The comment is being unpublished by the moderator.
  • "delete": The comment is being deleted by the moderator.

Related topics

7 functions implement hook_comment()

5 invocations of hook_comment()

File

developer/hooks/core.php, line 270
These are the hooks that are invoked by the Drupal core.

Code

function hook_comment(&$a1, $op) {
  if ($op == 'insert' || $op == 'update') {
    $nid = $a1['nid'];
  }

  cache_clear_all_like(drupal_url(array('id' => $nid)));
}

Comments

the 'unpublish' $op doesn't

the 'unpublish' $op doesn't actually exist. Which makes total sense, since the 'publish' $op does exist... wait... what?

A possible workaround is to use 'update', and check the value of the comment's status, to determine if has just been unpublished.

And the fun doesn't stop there...

If you're publishing/unpublishing from the comment/edit/* page, the $a1 in hook_comment() is going to be an array, but if you're doing that from the admin/content/comment/approval page, $a1 is actually the comment object.

Hope this saves someone else a few hours.

Apparently this doc page

Apparently this doc page isn't even remotely accurate.

http://drupal.org/node/314138#comment-4687412

Login or register to post comments