public function WorkspaceRequestSubscriber::onKernelController in Drupal 10
Same name and namespace in other branches
- 8 core/modules/workspaces/src/EventSubscriber/WorkspaceRequestSubscriber.php \Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber::onKernelController()
- 9 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\EventSubscriberCode
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);
  }
}