You are here

function comment_test_comment_links_alter in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/modules/comment_test/comment_test.module \comment_test_comment_links_alter()

Implements hook_comment_links_alter().

File

core/modules/comment/tests/modules/comment_test/comment_test.module, line 28
Dummy module implementing comment related hooks to test API interaction with the Comment module.

Code

function comment_test_comment_links_alter(array &$links, CommentInterface &$entity, array &$context) {

  // Allow tests to enable or disable this alter hook.
  if (!\Drupal::state()
    ->get('comment_test_links_alter_enabled', FALSE)) {
    return;
  }
  $links['comment_test'] = [
    '#theme' => 'links__comment__comment_test',
    '#attributes' => [
      'class' => [
        'links',
        'inline',
      ],
    ],
    '#links' => [
      'comment-report' => [
        'title' => t('Report'),
        'url' => Url::fromRoute('comment_test.report', [
          'comment' => $entity
            ->id(),
        ], [
          'query' => [
            'token' => \Drupal::getContainer()
              ->get('csrf_token')
              ->get("comment/{$entity->id()}/report"),
          ],
        ]),
      ],
    ],
  ];
}