function hook_comment_links_alter
Same name in other branches
- 8.9.x core/modules/comment/comment.api.php \hook_comment_links_alter()
- 10 core/modules/comment/comment.api.php \hook_comment_links_alter()
- 11.x 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
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"),
],
]),
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.