8.3.x comment.module comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
8.0.x comment.module comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
8.1.x comment.module comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
8.2.x comment.module comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
8.4.x comment.module comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)

Implements hook_entity_view().

File

core/modules/comment/comment.module, line 212
Enables users to comment on published content.

Code

function comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($entity instanceof FieldableEntityInterface && $view_mode == 'rss' && $display->getComponent('links')) {
    /** @var \Drupal\comment\CommentManagerInterface $comment_manager */
    $comment_manager = \Drupal::service('comment.manager');
    $fields = $comment_manager->getFields($entity->getEntityTypeId());
    foreach ($fields as $field_name => $detail) {
      if ($entity->hasField($field_name) && $entity->get($field_name)->status != CommentItemInterface::HIDDEN) {
        // Add a comments RSS element which is a URL to the comments of this
        // entity.
        $options = array(
          'fragment' => 'comments',
          'absolute' => TRUE,
        );
        $entity->rss_elements[] = array(
          'key' => 'comments',
          'value' => $entity->url('canonical', $options),
        );
      }
    }
  }
}