| 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
File
- developer/
hooks/ core.php, line 264 - These are the hooks that are invoked by the Drupal core.
Code
<?php
function hook_comment(&$a1, $op) {
if ($op == 'insert' || $op == 'update') {
$nid = $a1['nid'];
}
cache_clear_all_like(drupal_url(array('id' => $nid)));
}
?> Login or register to post comments
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
cache_clear_all_like() - what
cache_clear_all_like() - what is that? Did anyone see this function?
Same with drupal_url().
how does one change comment text programattically?
I've been up all night writing code to modify comment content using hook_comment.
Took care of arrays vs objects being passed, but I cannot override what gets written to the database.
How the heck do I do that?
I'd also like to change the text that is in the Subject: text input field and the Comment: textarea input field, but can *only* get them to change when previewing.
Anyone have any ideas how to filter out, say, bad words, or verboten spammer URLs, etc?
I'm really frustrated here.
Thanks.
Causes identified, patch proposed, issue raised.
I have checked the code, found some reasons for the trouble, created and proposed a patch to the 6.22/6.x-dev version of comment.module at http://drupal.org/node/1388082
I have tested it myself and found it working, so if someone does not want to wait for it to be accepted, find it there.