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:
\Drupal\comment\CommentViewBuilder::renderLinks()
\Drupal\comment\CommentViewBuilder::buildLinks()
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.
https://api.drupal.org/api/drupal/core!modules!comment!comment.api.php/function/hook_comment_links_alter/8.1.x