You are here

function hook_comment_links_alter in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/comment.api.php \hook_comment_links_alter()

Alter the links of a comment.

Parameters

array &$links: A renderable array representing the comment links.

\Drupal\comment\CommentInterface $entity: The comment being rendered.

array &$context: Various aspects of the context in which the comment links are going to be displayed, with the following keys:

  • 'view_mode': the view mode in which the comment is being viewed
  • 'langcode': the language in which the comment is being viewed
  • 'commented_entity': the entity to which the comment is attached

See also

\Drupal\comment\CommentViewBuilder::renderLinks()

\Drupal\comment\CommentViewBuilder::buildLinks()

Related topics

1 function implements hook_comment_links_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_test_comment_links_alter in core/modules/comment/tests/modules/comment_test/comment_test.module
Implements hook_comment_links_alter().
1 invocation of hook_comment_links_alter()
CommentLazyBuilders::renderLinks in core/modules/comment/src/CommentLazyBuilders.php
#lazy_builder callback; builds a comment's links.

File

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

Code

function hook_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
  $links['mymodule'] = [
    '#theme' => 'links__comment__mymodule',
    '#attributes' => [
      'class' => [
        'links',
        'inline',
      ],
    ],
    '#links' => [
      'comment-report' => [
        'title' => t('Report'),
        'url' => Url::fromRoute('comment_test.report', [
          'comment' => $entity
            ->id(),
        ], [
          'query' => [
            'token' => \Drupal::getContainer()
              ->get('csrf_token')
              ->get("comment/{$entity->id()}/report"),
          ],
        ]),
      ],
    ],
  ];
}