You are here

class ActiveWorkspaceCheck in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/Access/ActiveWorkspaceCheck.php \Drupal\workspaces\Access\ActiveWorkspaceCheck

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

Hierarchy

Expanded class hierarchy of ActiveWorkspaceCheck

1 file declares its use of ActiveWorkspaceCheck
ActiveWorkspaceCheckTest.php in core/modules/workspaces/tests/src/Unit/ActiveWorkspaceCheckTest.php
1 string reference to 'ActiveWorkspaceCheck'
workspaces.services.yml in core/modules/workspaces/workspaces.services.yml
core/modules/workspaces/workspaces.services.yml
1 service uses ActiveWorkspaceCheck
access_check.workspaces.active_workspace in core/modules/workspaces/workspaces.services.yml
Drupal\workspaces\Access\ActiveWorkspaceCheck

File

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

Namespace

Drupal\workspaces\Access
View source
class ActiveWorkspaceCheck implements AccessInterface {

  /**
   * The workspace manager.
   *
   * @var \Drupal\workspaces\WorkspaceManagerInterface
   */
  protected $workspaceManager;

  /**
   * Constructs a new ActiveWorkspaceCheck.
   *
   * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
   *   The workspace manager.
   */
  public function __construct(WorkspaceManagerInterface $workspace_manager) {
    $this->workspaceManager = $workspace_manager;
  }

  /**
   * Checks access.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  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',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActiveWorkspaceCheck::$workspaceManager protected property The workspace manager.
ActiveWorkspaceCheck::access public function Checks access.
ActiveWorkspaceCheck::__construct public function Constructs a new ActiveWorkspaceCheck.