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()

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

entity_crud_hook_test_comment_presave in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
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);
}