/Drupal 8

function hook_comment_links_alter

hook_comment_links_alter(array &$links, CommentInterface $entity, array &$context)

Alter the links of a comment.


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



Related topics

Define functions that alter the behavior of Drupal core.


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


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")]]),

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.