Same name and namespace in other branches
  1. 4.6.x developer/hooks/core.php \hook_comment()
  2. 4.7.x developer/hooks/core.php \hook_comment()
  3. 6.x developer/hooks/core.php \hook_comment()

Act on comments.

This hook allows modules to extend the comments system.

Parameters

$a1: Dependent on the action being performed.

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

$op: What kind of action is 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.
  • "form": The comment form is about to be shown. Modules may add fields to the form at this point.
  • "validate": The user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check or even modify the node. 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.

Return value

Dependent on the action being performed.

  • For "form", an array of form elements to add to the comment form.
  • For all other operations, nothing.

Related topics

4 functions implement hook_comment()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

chameleon_comment in themes/chameleon/chameleon.theme
comment_invoke_comment in modules/comment/comment.module
Invoke a hook_comment() operation in all modules.
phptemplate_comment in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_comment function to be passed into a pluggable template engine.
theme_comment in modules/comment/comment.module

File

developer/hooks/core.php, line 129
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,
  )));
}