You are here

function comment_alter_comment_links_alter in Comment Alter 8

Implements hook_comment_links_alter().

File

./comment_alter.module, line 521
Allows to alter entities from comment form.

Code

function comment_alter_comment_links_alter(array &$links, CommentInterface $comment, array &$context) {

  // Since Diff module shows the differences for nodes only so create diff link
  // for nodes.
  $parent_entity = $comment
    ->getCommentedEntity();
  if ($parent_entity
    ->getEntityTypeId() == 'node') {
    $comment_field = $parent_entity
      ->getFieldDefinition($comment
      ->getFieldName());
    if (!$comment_field
      ->getThirdPartySetting('comment_alter', 'comment_alter_diff_link', FALSE)) {
      return;
    }
    $links['comment_alter'] = [
      '#attributes' => [
        'class' => [
          'links',
          'inline',
        ],
      ],
      '#links' => [
        'comment-diff' => [
          'title' => t('Diff'),
          'url' => Url::fromUserInput('/node/' . $parent_entity
            ->id() . '/revisions/view/' . $comment->comment_alter['old_vid'] . '/' . $comment->comment_alter['new_vid']),
        ],
      ],
    ];
  }
}