function hook_comment_create

Act on a newly created comment.

This hook runs after a new comment object has just been instantiated. It can be used to set initial values, e.g. to provide defaults.

Parameters

\Drupal\comment\Plugin\Core\Entity\Comment $comment: The comment object.

Related topics

1 function implements hook_comment_create()

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_create in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_comment_create().

File

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

Code

function hook_comment_create(\Drupal\comment\Plugin\Core\Entity\Comment $comment) {
  if (!isset($comment->foo)) {
    $comment->foo = 'some_initial_value';
  }
}