function CommentLazyBuilders::renderLinks

Same name in other branches
  1. 9 core/modules/comment/src/CommentLazyBuilders.php \Drupal\comment\CommentLazyBuilders::renderLinks()
  2. 10 core/modules/comment/src/CommentLazyBuilders.php \Drupal\comment\CommentLazyBuilders::renderLinks()
  3. 11.x 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 137

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 = [
        '#theme' => 'links__comment',
        '#pre_render' => [
            [
                Link::class,
                'preRenderLinks',
            ],
        ],
        '#attributes' => [
            'class' => [
                'links',
                'inline',
            ],
        ],
    ];
    if (!$is_in_preview) {
        
        /** @var \Drupal\comment\CommentInterface $entity */
        $entity = $this->entityTypeManager
            ->getStorage('comment')
            ->load($comment_entity_id);
        if ($commented_entity = $entity->getCommentedEntity()) {
            $links['comment'] = $this->buildLinks($entity, $commented_entity);
        }
        // Allow other modules to alter the comment links.
        $hook_context = [
            'view_mode' => $view_mode,
            'langcode' => $langcode,
            'commented_entity' => $commented_entity,
        ];
        $this->moduleHandler
            ->alter('comment_links', $links, $entity, $hook_context);
    }
    return $links;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.