You are here

class FilebrowserAccessCheck in Filebrowser 8.2

Same name and namespace in other branches
  1. 3.x src/Access/FilebrowserAccessCheck.php \Drupal\filebrowser\Access\FilebrowserAccessCheck

Checks access to filebrowser page.

Hierarchy

Expanded class hierarchy of FilebrowserAccessCheck

1 string reference to 'FilebrowserAccessCheck'
filebrowser.services.yml in ./filebrowser.services.yml
filebrowser.services.yml
1 service uses FilebrowserAccessCheck
filebrowser.action.access_checker in ./filebrowser.services.yml
Drupal\filebrowser\Access\FilebrowserAccessCheck

File

src/Access/FilebrowserAccessCheck.php, line 14

Namespace

Drupal\filebrowser\Access
View source
class FilebrowserAccessCheck implements AccessInterface {

  /**
   * A custom access check.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   * @param RouteMatchInterface $route_match
   * @return AccessResult
   */
  public function access(RouteMatchInterface $route_match, AccountInterface $account) {
    if ($op = $route_match
      ->getParameter('op')) {
      if ($permission = static::mapActionToPermission($op)) {
        return AccessResult::allowedIfHasPermission($account, $permission);
      }
    }
    return AccessResult::neutral();
  }
  protected static function mapActionToPermission($action) {
    $permissions = [
      'delete' => Common::DELETE_FILES,
      'description' => Common::RENAME_FILES,
      'folder' => Common::CREATE_FOLDER,
      'upload' => Common::FILE_UPLOAD,
      'rename' => Common::RENAME_FILES,
      'archive' => Common::DOWNLOAD_ARCHIVE,
    ];
    return isset($permissions[$action]) ? $permissions[$action] : NULL;
  }

}

Members