comment_test.module 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @file
  4. * Dummy module implementing comment related hooks to test API interaction with
  5. * the Comment module.
  6. */
  7. use Drupal\comment\CommentInterface;
  8. use Drupal\Core\Url;
  9. /**
  10. * Implements hook_entity_type_alter().
  11. */
  12. function comment_test_entity_type_alter(array &$entity_types) {
  13. /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  14. if (\Drupal::languageManager()->isMultilingual()) {
  15. // Enable language handling for comment fields.
  16. $translation = $entity_types['comment']->get('translation');
  17. $translation['comment_test'] = TRUE;
  18. $entity_types['comment']->set('translation', $translation);
  19. }
  20. }
  21. /**
  22. * Implements hook_comment_links_alter().
  23. */
  24. function comment_test_comment_links_alter(array &$links, CommentInterface &$entity, array &$context) {
  25. // Allow tests to enable or disable this alter hook.
  26. if (!\Drupal::state()->get('comment_test_links_alter_enabled', FALSE)) {
  27. return;
  28. }
  29. $links['comment_test'] = [
  30. '#theme' => 'links__comment__comment_test',
  31. '#attributes' => ['class' => ['links', 'inline']],
  32. '#links' => [
  33. 'comment-report' => [
  34. 'title' => t('Report'),
  35. 'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
  36. ],
  37. ],
  38. ];
  39. }