You are here

public function WorkspaceRequestSubscriber::onKernelController in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber::onKernelController()

Sets the cache key on the alias manager cache decorator.

KernelEvents::CONTROLLER is used in order to be executed after routing.

Parameters

\Symfony\Component\HttpKernel\Event\ControllerEvent $event: The Event to process.

File

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

Class

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

Namespace

Drupal\workspaces\EventSubscriber

Code

public function onKernelController(ControllerEvent $event) {

  // Set the cache key on the alias manager cache decorator.
  if ($event
    ->isMainRequest() && $this->workspaceManager
    ->hasActiveWorkspace()) {
    $cache_key = $this->workspaceManager
      ->getActiveWorkspace()
      ->id() . ':' . rtrim($this->currentPath
      ->getPath($event
      ->getRequest()), '/');
    $this->aliasManager
      ->setCacheKey($cache_key);
  }
}