diff --git a/EventSubscriber/NavigationInvalidationSubscriber.php b/EventSubscriber/NavigationInvalidationSubscriber.php index 5d60fec..135bdb3 100644 --- a/EventSubscriber/NavigationInvalidationSubscriber.php +++ b/EventSubscriber/NavigationInvalidationSubscriber.php @@ -91,51 +91,53 @@ public static function getSubscribedEvents() public function collectNavigationContextBeforePublishing(PublishEvent $event): void { - $path = $this->documentInspector->getPath($event->getDocument()); - $this->collectNavigationContexts($path, $event->getLocale()); + $this->collectNavigationContexts($event->getDocument(), $event->getLocale()); } public function collectNavigationContextBeforeUnpublishing(UnpublishEvent $event): void { - $path = $this->documentInspector->getPath($event->getDocument()); - $this->collectNavigationContexts($path, $event->getLocale()); + $this->collectNavigationContexts($event->getDocument(), $event->getLocale()); } public function collectNavigationContextBeforeRemoving(RemoveEvent $event): void { - $document = $event->getDocument(); - $path = $this->documentInspector->getPath($event->getDocument()); - foreach ($this->documentInspector->getLocales($document) as $locale) { - $this->collectNavigationContexts($path, $locale); - } + $this->collectNavigationContexts($event->getDocument(), null); } public function collectNavigationContextBeforeRemovingLocale(RemoveLocaleEvent $event): void { - $path = $this->documentInspector->getPath($event->getDocument()); - $this->collectNavigationContexts($path, $event->getLocale()); + $this->collectNavigationContexts($event->getDocument(), $event->getLocale()); } - public function collectNavigationContexts(string $path, string $locale): void + private function collectNavigationContexts(object $document, ?string $eventLocale): void { + $path = $this->documentInspector->getPath($document); + $locales = $eventLocale ? [$eventLocale] : $this->documentInspector->getLocales($document); + $defaultNode = $this->defaultSession->getNode($path); $liveNode = $this->liveSession->getNode($path); - $propertyName = $this->propertyEncoder->localizedContentName('navContexts', $locale); - $liveNavigationContexts = []; - $defaultNavigationContexts = []; - if ($liveNode->hasProperty($propertyName)) { - $liveNavigationContexts = $liveNode->getProperty($propertyName)->getValue(); + foreach ($locales as $locale) { + $propertyName = $this->propertyEncoder->localizedContentName('navContexts', $locale); + $liveNavigationContexts = []; + $defaultNavigationContexts = []; + + if ($liveNode->hasProperty($propertyName)) { + $liveNavigationContexts = $liveNode->getProperty($propertyName)->getValue(); + } + + if ($defaultNode->hasProperty($propertyName)) { + $defaultNavigationContexts = $defaultNode->getProperty($propertyName)->getValue(); + } + + $this->navigationContexts = \array_unique( + \array_merge( + $this->navigationContexts, + $liveNavigationContexts, + $defaultNavigationContexts + ) + ); } - if ($defaultNode->hasProperty($propertyName)) { - $defaultNavigationContexts = $defaultNode->getProperty($propertyName)->getValue(); - } - - $this->navigationContexts = \array_merge( - $this->navigationContexts, - $liveNavigationContexts, - $defaultNavigationContexts - ); } public function invalidateNavigationContexts(): void diff --git a/UPGRADE.md b/UPGRADE.md index bd37249..17b4590 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade +## 0.9.0 + +### Make NavigationInvalidationSubscriber::collectNavigationContexts method private + ## 0.6.0 ### Change constructor arguments of SingleSnippetSelectionResolver