hook_comment_links_alter

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

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")]]),
      ),
    ),
  );
}
doc_Drupal
2016-10-29 09:17:51
Comments
Leave a Comment

Please login to continue.