function WorkspaceRequestSubscriber::onKernelController

Same name and namespace in other branches
  1. 8.9.x 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);
  }
}

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