hook_comment_links_alter(array &$links, CommentInterface $entity, array &$context)
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
- Hooks
- Define functions that alter the behavior of Drupal core.
File
- core/modules/comment/comment.api.php, line 33
- Hooks provided by the Comment module.
Code
1 2 3 4 5 6 7 8 9 10 11 12 | function hook_comment_links_alter( array & $links , CommentInterface $entity , array & $context ) { $links [ 'mymodule' ] = array ( '#theme' => 'links__comment__mymodule' , '#attributes' => array ( 'class' => array ( 'links' , 'inline' )), '#links' => array ( 'comment-report' => array ( 'title' => t( 'Report' ), 'url' => Url::fromRoute( 'comment_test.report' , [ 'comment' => $entity ->id()], [ 'query' => [ 'token' => \Drupal::getContainer()->get( 'csrf_token' )->get( "comment/{$entity->id()}/report" )]]), ), ), ); } |
Please login to continue.