function WorkspaceSwitchSubscriber::onWorkspaceSwitch

Clears various static caches when a new workspace is activated.

Parameters

\Drupal\workspaces\Event\WorkspaceSwitchEvent $event: An event object.

File

core/modules/workspaces/src/EventSubscriber/WorkspaceSwitchSubscriber.php, line 32

Class

WorkspaceSwitchSubscriber
Provides a event subscriber for reacting to workspace activation.

Namespace

Drupal\workspaces\EventSubscriber

Code

public function onWorkspaceSwitch(WorkspaceSwitchEvent $event) : void {
  // Clear the static cache for supported entity types.
  $cache_tags_to_invalidate = [];
  foreach (array_keys($this->workspaceInfo
    ->getSupportedEntityTypes()) as $entity_type_id) {
    $cache_tags_to_invalidate[] = 'entity.memory_cache:' . $entity_type_id;
  }
  $this->entityMemoryCache
    ->invalidateTags($cache_tags_to_invalidate);
  // Clear the static cache for path aliases.
  $this->aliasManager?->cacheClear();
}

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