function photos_photos_access in Album Photos 8.5
Same name and namespace in other branches
- 8.4 photos.module \photos_photos_access()
- 6.2 photos.module \photos_photos_access()
- 7.3 photos.module \photos_photos_access()
- 6.0.x photos.module \photos_photos_access()
Implements hook_photos_access().
File
- ./
photos.module, line 31 - Implementation of photos.module.
Code
function photos_photos_access() {
if (\Drupal::config('photos.settings')
->get('photos_access_photos')) {
$node = \Drupal::routeMatch()
->getParameter('node');
if (is_numeric($node)) {
// Views only provides the numeric nid.
// @todo find out if there is a better way to do this in views?
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($node);
}
if ($node && $node instanceof NodeInterface && $node
->getType() == 'photos') {
// Return album node id.
return [
$node
->id(),
];
}
elseif ($entityId = \Drupal::routeMatch()
->getRawParameter('photos_image')) {
// If viewing image check access to album node id.
$db = \Drupal::database();
$nid = $db
->query("SELECT album_id FROM {photos_image_field_data} WHERE id = :id", [
':id' => $entityId,
])
->fetchField();
return [
$nid,
];
}
}
return [];
}