You are here

function quote_node_links_alter in Quote 8.2

Implements hook_node_links_alter().

File

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

Code

function quote_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
  $config = \Drupal::config('quote.settings');

  // Get comments field name.
  $comment_field_name = '';
  $comment_fields = \Drupal::service('comment.manager')
    ->getFields('node');
  foreach ($comment_fields as $key => $value) {
    $entity
      ->hasField($key) ? $comment_field_name = $key : '';
  }
  if ($comment_field_name) {
    if (\Drupal::currentUser()
      ->hasPermission('post comments') && \Drupal::currentUser()
      ->hasPermission('use quote') && in_array($entity
      ->bundle(), array_filter($config
      ->get('quote_allow_types'))) && $entity
      ->get($comment_field_name)->status == CommentItemInterface::OPEN) {
      if ($config
        ->get('quote_modes_quote_sel')) {
        $link['node-quote-sel'] = [
          'title' => t('quote selected'),
          'url' => Url::fromUserInput('#', [
            'fragment' => '#',
          ]),
        ];
        $links['node']['#links']['node-quote-sel'] = $link['node-quote-sel'];
      }
      if ($config
        ->get('quote_modes_quote_all')) {
        $link['node-quote-all'] = [
          'title' => t('quote all'),
          'url' => Url::fromUserInput('#', [
            'fragment' => '#',
          ]),
        ];
        $links['node']['#links']['node-quote-all'] = $link['node-quote-all'];
      }
    }
  }
}