function hook_comment_presave

Act on a comment being inserted or updated.

This hook is invoked from $comment->save() before the comment is saved to the database.

Parameters

Drupal\comment\Comment $comment: The comment object.

Related topics

1 function implements hook_comment_presave()

File

drupal/core/modules/comment/comment.api.php, line 24
Hooks provided by the Comment module.

Code

function hook_comment_presave(Drupal\comment\Comment $comment) {

  // Remove leading & trailing spaces from the comment subject.
  $comment->subject->value = trim($comment->subject->value);
}