You are here

function filebrowser_node_access in Filebrowser 3.x

Same name and namespace in other branches
  1. 8.2 filebrowser.module \filebrowser_node_access()
  2. 8 filebrowser.module \filebrowser_node_access()
  3. 7.4 filebrowser.module \filebrowser_node_access()
  4. 7.2 filebrowser.module \filebrowser_node_access()
  5. 7.3 filebrowser.module \filebrowser_node_access()

Implements hook_node_access. @inheritdoc

File

./filebrowser.module, line 268

Code

function filebrowser_node_access(NodeInterface $node, $op, AccountInterface $account) {
  if ($node
    ->bundle() == 'dir_listing') {
    switch ($op) {
      case 'view':
        return AccessResult::forbiddenIf(!$account
          ->hasPermission(Common::VIEW_LISTINGS));
      case 'create':
        return AccessResult::forbiddenIf(!$account
          ->hasPermission(Common::CREATE_LISTING));
      case 'update':
        $has_permission = $account
          ->hasPermission(Common::EDIT_ANY_LISTINGS) || $account
          ->hasPermission(Common::EDIT_OWN_LISTINGS) && $account
          ->id() == $node
          ->getOwnerId();
        return AccessResult::forbiddenIf(!$has_permission);
      case 'delete':
        $has_permission = $account
          ->hasPermission(Common::DELETE_ANY_LISTINGS) || $account
          ->hasPermission(Common::DELETE_OWN_LISTINGS) && $account
          ->id() == $node
          ->getOwnerId();
        return AccessResult::forbiddenIf(!$has_permission);
      default:
        return AccessResult::neutral();
    }
  }
  else {
    return AccessResult::neutral();
  }
}