function hook_comment_view

Act on a comment that is being assembled before rendering.

Parameters

\Drupal\comment\Plugin\Core\Entity\Comment $comment $comment: Passes in the comment the action is being performed on.

\Drupal\entity\Plugin\Core\Entity\EntityDisplay $display: The entity_display object holding the display options configured for the comment components.

$view_mode: View mode, e.g. 'full', 'teaser'...

$langcode: The language code used for rendering.

See also

hook_entity_view()

Related topics

File

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

Code

function hook_comment_view(\Drupal\comment\Plugin\Core\Entity\Comment $comment, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {

  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // node type in hook_field_extra_fields().
  if ($display
    ->getComponent('mymodule_addition')) {
    $comment->content['mymodule_addition'] = array(
      '#markup' => mymodule_addition($comment),
      '#theme' => 'mymodule_my_additional_field',
    );
  }
}