Skip to content

Commit

Permalink
Implement suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-rath committed Sep 20, 2022
1 parent 3825db7 commit 7dbc0d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
56 changes: 28 additions & 28 deletions EventSubscriber/NavigationInvalidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +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 = $locale ?
$this->propertyEncoder->localizedContentName('navContexts', $locale) :
$this->propertyEncoder->contentName('navContexts');
$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
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade

## 0.9.0

### Make NavigationInvalidationSubscriber::collectNavigationContexts method private

## 0.6.0

### Change constructor arguments of SingleSnippetSelectionResolver
Expand Down

0 comments on commit 7dbc0d1

Please sign in to comment.