comment.api.php 1.4 KB

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