function photos_access_node_access in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 photos_access/photos_access.module \photos_access_node_access()
- 8.4 photos_access/photos_access.module \photos_access_node_access()
Implements hook_ENTITY_TYPE_access().
File
- photos_access/
photos_access.module, line 429 - Implementation of photos_access.module.
Code
function photos_access_node_access(EntityInterface $entity, $operation, AccountInterface $account) {
if (\Drupal::config('photos.settings')
->get('photos_access_' . $entity
->getType())) {
// Check if album password is required.
photos_access_request_album_password();
// Check role access.
if (isset($entity->photos_privacy)) {
if ($entity->photos_privacy['viewid'] == 4 && isset($entity->photos_privacy['roles'])) {
$account_roles = $account
->getRoles();
// Check if role is selected for this album.
if (count(array_intersect($account_roles, $entity->photos_privacy['roles'])) !== 0) {
// Role access.
switch ($operation) {
case 'view':
return AccessResult::allowedIf($account
->hasPermission('view photo'))
->cachePerPermissions()
->addCacheableDependency($entity);
case 'update':
return AccessResult::allowedIf($account
->hasPermission('edit own photo'))
->cachePerPermissions()
->addCacheableDependency($entity);
case 'delete':
return AccessResult::allowedIf($account
->hasPermission('delete own photo'))
->cachePerPermissions()
->addCacheableDependency($entity);
}
}
}
}
}
// No opinion.
return AccessResult::neutral();
}