You are here

function photos_comment_links_alter in Album Photos 8.4

Same name and namespace in other branches
  1. 6.0.x photos.module \photos_comment_links_alter()

Implements hook_comment_links_alter().

File

./photos.module, line 1009
Implementation of photos.module.

Code

function photos_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
  $current_path = \Drupal::service('path.current')
    ->getPath();
  $path_args = explode('/', $current_path);
  if ($entity
    ->getCommentedEntityTypeId() == 'node' && $context['commented_entity']
    ->getType() == 'photos' && $path_args[1] != 'photos') {
    $db = \Drupal::database();
    $fid = $db
      ->select('photos_comment', 'v')
      ->fields('v', [
      'fid',
    ])
      ->condition('v.cid', $entity
      ->id())
      ->execute()
      ->fetchField();
    if (!empty($fid)) {
      $links['photos'] = [
        '#theme' => 'links__comment__photos',
        '#attributes' => [
          'class' => [
            'links',
            'inline',
          ],
        ],
        '#links' => [
          'comment-report' => [
            'title' => t('View image'),
            'url' => Url::fromRoute('photos.image', [
              'file' => $fid,
            ]),
          ],
        ],
      ];
    }
  }
}