You are here

public function ActiveWorkspaceCheck::access in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/Access/ActiveWorkspaceCheck.php \Drupal\workspaces\Access\ActiveWorkspaceCheck::access()
  2. 9 core/modules/workspaces/src/Access/ActiveWorkspaceCheck.php \Drupal\workspaces\Access\ActiveWorkspaceCheck::access()

Checks access.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/modules/workspaces/src/Access/ActiveWorkspaceCheck.php, line 41

Class

ActiveWorkspaceCheck
Determines access to routes based on the presence of an active workspace.

Namespace

Drupal\workspaces\Access

Code

public function access(Route $route) {
  if (!$route
    ->hasRequirement('_has_active_workspace')) {
    return AccessResult::neutral();
  }
  $required_value = filter_var($route
    ->getRequirement('_has_active_workspace'), FILTER_VALIDATE_BOOLEAN);
  return AccessResult::allowedIf($required_value === $this->workspaceManager
    ->hasActiveWorkspace())
    ->addCacheContexts([
    'workspace',
  ]);
}