You are here

function quote_comment_links_alter in Quote 8.2

Implements hook_comment_links_alter().

File

./quote.module, line 61
Allows users to quote posts or comments.

Code

function quote_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
  $config = \Drupal::config('quote.settings');
  if (\Drupal::currentUser()
    ->hasPermission('post comments') && \Drupal::currentUser()
    ->hasPermission('use quote') && $config
    ->get('quote_allow_comments') && in_array($entity
    ->getCommentedEntity()
    ->bundle(), array_filter($config
    ->get('quote_allow_types')))) {
    if ($config
      ->get('quote_modes_quote_sel')) {
      $link['comment-quote-sel'] = [
        'title' => t('quote selected'),
        'url' => Url::fromUserInput('#', [
          'fragment' => '#',
        ]),
      ];
      $links['comment']['#links']['comment-quote-sel'] = $link['comment-quote-sel'];
    }
    if ($config
      ->get('quote_modes_quote_all')) {
      $link['comment-quote-all'] = [
        'title' => t('quote all'),
        'url' => Url::fromUserInput('#', [
          'fragment' => '#',
        ]),
      ];
      $links['comment']['#links']['comment-quote-all'] = $link['comment-quote-all'];
    }
    if ($config
      ->get('quote_modes_quote_reply_all')) {
      $nid = $entity
        ->getCommentedEntityId();
      $cid = $entity
        ->id();
      $comment_field_name = $entity
        ->getFieldName();
      $link['comment-quote-all-reply'] = [
        'title' => t('reply and quote all'),
        'url' => Url::fromUserInput('/comment/reply/node/' . $nid . '/' . $comment_field_name . '/' . $cid),
        'query' => [
          'comment-quote-all-reply' => $cid,
        ],
      ];
      $links['comment']['#links']['comment-quote-all-reply'] = $link['comment-quote-all-reply'];
    }
  }
}