function photos_node_access in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 photos.module \photos_node_access()
- 8.4 photos.module \photos_node_access()
- 7.3 photos.module \photos_node_access()
Implements hook_ENTITY_TYPE_access().
File
- ./photos.module, line 61 
- Implementation of photos.module.
Code
function photos_node_access(EntityInterface $entity, $operation, AccountInterface $account) {
  // Check user access.
  switch ($operation) {
    case 'view':
      if ($account
        ->hasPermission('edit any photo')) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      return AccessResult::neutral();
    case 'create':
      return AccessResult::allowedIfHasPermission($account, 'create photo');
    case 'update':
      if ($account
        ->hasPermission('edit any photo') || $account
        ->hasPermission('edit own photo') && $account
        ->id() == $entity
        ->getOwnerId()) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      return AccessResult::neutral();
    case 'delete':
      if ($account
        ->hasPermission('delete any photo') || $account
        ->hasPermission('delete own photo') && $account
        ->id() == $entity
        ->getOwnerId()) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
      return AccessResult::neutral();
    default:
      // No opinion.
      return AccessResult::neutral();
  }
}