class WorkspaceRequestSubscriber

Same name in other branches
  1. 9 core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber
  2. 8.9.x core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber
  3. 11.x core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber

Provides a event subscriber for setting workspace-specific cache keys.

@internal

Hierarchy

  • class \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of WorkspaceRequestSubscriber

1 file declares its use of WorkspaceRequestSubscriber
WorkspaceRequestSubscriberTest.php in core/modules/workspaces/tests/src/Unit/WorkspaceRequestSubscriberTest.php
1 string reference to 'WorkspaceRequestSubscriber'
workspaces.services.yml in core/modules/workspaces/workspaces.services.yml
core/modules/workspaces/workspaces.services.yml
1 service uses WorkspaceRequestSubscriber
workspaces.workspace_subscriber in core/modules/workspaces/workspaces.services.yml
Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber

File

core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php, line 17

Namespace

Drupal\workspaces\EventSubscriber
View source
class WorkspaceRequestSubscriber implements EventSubscriberInterface {
    public function __construct(RouteProviderInterface $routeProvider, WorkspaceManagerInterface $workspaceManager) {
    }
    
    /**
     * Adds the active workspace as a cache key part to the route provider.
     *
     * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
     *   An event object.
     */
    public function onKernelRequest(RequestEvent $event) {
        if ($this->workspaceManager
            ->hasActiveWorkspace() && $this->routeProvider instanceof CacheableRouteProviderInterface) {
            $this->routeProvider
                ->addExtraCacheKeyPart('workspace', $this->workspaceManager
                ->getActiveWorkspace()
                ->id());
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        // Use a priority of 33 in order to run before Symfony's router listener.
        // @see \Symfony\Component\HttpKernel\EventListener\RouterListener::getSubscribedEvents()
        $events[KernelEvents::REQUEST][] = [
            'onKernelRequest',
            33,
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
WorkspaceRequestSubscriber::getSubscribedEvents public static function
WorkspaceRequestSubscriber::onKernelRequest public function Adds the active workspace as a cache key part to the route provider.
WorkspaceRequestSubscriber::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.