class WorkspaceSwitchSubscriber
Provides a event subscriber for reacting to workspace activation.
@internal
Hierarchy
- class \Drupal\workspaces\EventSubscriber\WorkspaceSwitchSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of WorkspaceSwitchSubscriber
File
-
core/
modules/ workspaces/ src/ EventSubscriber/ WorkspaceSwitchSubscriber.php, line 17
Namespace
Drupal\workspaces\EventSubscriberView source
class WorkspaceSwitchSubscriber implements EventSubscriberInterface {
public function __construct(protected readonly WorkspaceInformationInterface $workspaceInfo, #[Autowire(service: 'entity.memory_cache')] protected readonly MemoryCacheInterface $entityMemoryCache, protected readonly ?AliasManagerInterface $aliasManager = NULL) {
}
/**
* Clears various static caches when a new workspace is activated.
*
* @param \Drupal\workspaces\Event\WorkspaceSwitchEvent $event
* An event object.
*/
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();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[WorkspaceSwitchEvent::class][] = 'onWorkspaceSwitch';
return $events;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| WorkspaceSwitchSubscriber::getSubscribedEvents | public static | function | |
| WorkspaceSwitchSubscriber::onWorkspaceSwitch | public | function | Clears various static caches when a new workspace is activated. |
| WorkspaceSwitchSubscriber::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.