You are here

public function CommentLazyBuilders::renderLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/CommentLazyBuilders.php \Drupal\comment\CommentLazyBuilders::renderLinks()

#lazy_builder callback; builds a comment's links.

Parameters

string $comment_entity_id: The comment entity ID.

string $view_mode: The view mode in which the comment entity is being viewed.

string $langcode: The language in which the comment entity is being viewed.

bool $is_in_preview: Whether the comment is currently being previewed.

Return value

array A renderable array representing the comment links.

File

core/modules/comment/src/CommentLazyBuilders.php, line 133
Contains \Drupal\comment\CommentLazyBuilders.

Class

CommentLazyBuilders
Defines a service for comment #lazy_builder callbacks.

Namespace

Drupal\comment

Code

public function renderLinks($comment_entity_id, $view_mode, $langcode, $is_in_preview) {
  $links = array(
    '#theme' => 'links__comment',
    '#pre_render' => array(
      'drupal_pre_render_links',
    ),
    '#attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  );
  if (!$is_in_preview) {

    /** @var \Drupal\comment\CommentInterface $entity */
    $entity = $this->entityManager
      ->getStorage('comment')
      ->load($comment_entity_id);
    $commented_entity = $entity
      ->getCommentedEntity();
    $links['comment'] = $this
      ->buildLinks($entity, $commented_entity);

    // Allow other modules to alter the comment links.
    $hook_context = array(
      'view_mode' => $view_mode,
      'langcode' => $langcode,
      'commented_entity' => $commented_entity,
    );
    $this->moduleHandler
      ->alter('comment_links', $links, $entity, $hook_context);
  }
  return $links;
}