function photos_comment_links_alter in Album Photos 6.0.x
Same name and namespace in other branches
- 8.4 photos.module \photos_comment_links_alter()
Implements hook_comment_links_alter().
If upgraded from D7 or 8.x-4.x this adds the image link to the comments on the photo album node.
File
- ./
photos.module, line 1505 - Implementation of photos.module.
Code
function photos_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
if (\Drupal::database()
->schema()
->tableExists('photos_comment')) {
$cid = $entity
->id();
// Check if any image files are linked to this comment.
$fid = \Drupal::database()
->query("SELECT fid FROM {photos_comment} WHERE cid = :cid", [
':cid' => $cid,
])
->fetchField();
if ($fid) {
/** @var \Drupal\photos\PhotosImageStorageInterface $photos_image_storage */
$photos_image_storage = \Drupal::entityTypeManager()
->getStorage('photos_image');
/** @var \Drupal\photos\PhotosImageInterface $photos_image */
$photos_image_results = $photos_image_storage
->getQuery()
->condition('field_image.target_id', $fid)
->execute();
$photos_image = $photos_image_storage
->load(reset($photos_image_results));
$page_image_id = \Drupal::routeMatch()
->getRawParameter('photos_image');
if ($photos_image && $photos_image
->id() && $page_image_id != $photos_image
->id()) {
$links['photos'] = [
'#theme' => 'links__comment__photos',
'#attributes' => [
'class' => [
'links',
'inline',
],
],
'#links' => [
'photos-image' => [
'title' => t('View image'),
'url' => Url::fromRoute('entity.photos_image.canonical', [
'node' => $photos_image
->getAlbumId(),
'photos_image' => $photos_image
->id(),
]),
],
],
];
}
}
}
}