You are here

function photos_node_access in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos.module \photos_node_access()
  2. 7.3 photos.module \photos_node_access()
  3. 6.0.x photos.module \photos_node_access()

Implements hook_node_access().

File

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

Code

function photos_node_access(NodeInterface $node, $op, AccountInterface $account) {

  // Check user access.
  switch ($op) {
    case 'create':
      return AccessResult::allowedIfHasPermission($account, 'create photo');
    case 'update':
      if ($account
        ->hasPermission('edit any photo') || $account
        ->hasPermission('edit own photo') && $account
        ->id() == $node
        ->getOwnerId()) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
    case 'delete':
      if ($account
        ->hasPermission('delete any photo') || $account
        ->hasPermission('delete own photo') && $account
        ->id() == $node
        ->getOwnerId()) {
        return AccessResult::allowed()
          ->cachePerPermissions();
      }
    default:

      // No opinion.
      return AccessResult::neutral();
  }
}