Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Hooks provided by the Comment module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\comment\CommentInterface;
|
Chris@0
|
9 use Drupal\Core\Url;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * @addtogroup hooks
|
Chris@0
|
13 * @{
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Alter the links of a comment.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @param array &$links
|
Chris@0
|
20 * A renderable array representing the comment links.
|
Chris@0
|
21 * @param \Drupal\comment\CommentInterface $entity
|
Chris@0
|
22 * The comment being rendered.
|
Chris@0
|
23 * @param array &$context
|
Chris@0
|
24 * Various aspects of the context in which the comment links are going to be
|
Chris@0
|
25 * displayed, with the following keys:
|
Chris@0
|
26 * - 'view_mode': the view mode in which the comment is being viewed
|
Chris@0
|
27 * - 'langcode': the language in which the comment is being viewed
|
Chris@0
|
28 * - 'commented_entity': the entity to which the comment is attached
|
Chris@0
|
29 *
|
Chris@0
|
30 * @see \Drupal\comment\CommentViewBuilder::renderLinks()
|
Chris@0
|
31 * @see \Drupal\comment\CommentViewBuilder::buildLinks()
|
Chris@0
|
32 */
|
Chris@0
|
33 function hook_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
|
Chris@0
|
34 $links['mymodule'] = [
|
Chris@0
|
35 '#theme' => 'links__comment__mymodule',
|
Chris@0
|
36 '#attributes' => ['class' => ['links', 'inline']],
|
Chris@0
|
37 '#links' => [
|
Chris@0
|
38 'comment-report' => [
|
Chris@0
|
39 'title' => t('Report'),
|
Chris@0
|
40 'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
|
Chris@0
|
41 ],
|
Chris@0
|
42 ],
|
Chris@0
|
43 ];
|
Chris@0
|
44 }
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * @} End of "addtogroup hooks".
|
Chris@0
|
48 */
|