From ae9eda4515252007ece8802375d743c3a5606372 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Fri, 24 Feb 2023 15:33:07 +0100 Subject: [PATCH] BUGFIX: Load node variants in proper context --- Classes/Keeper.php | 54 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/Classes/Keeper.php b/Classes/Keeper.php index 654b3b4..b239a5a 100644 --- a/Classes/Keeper.php +++ b/Classes/Keeper.php @@ -1,7 +1,10 @@ enabled !== true || !$this->managedProperties($node, $propertyName)) { @@ -38,15 +48,13 @@ public function sync(NodeInterface $node, string $propertyName, $oldValue, $newV $currentDimensions = $node->getDimensions(); $this->systemLogger->debug(\vsprintf('Synchronize property %s start in %s', [$propertyName, \json_encode($currentDimensions)])); - \array_map(function (NodeInterface $nodeVariant) use ($propertyName, $newValue, $currentDimensions) { - if ($nodeVariant->getDimensions() === $currentDimensions) { - return; - } + \array_map(function (NodeInterface $nodeVariant) use ($propertyName, $newValue) { $this->systemLogger->debug(\vsprintf('Synchronize property %s to node variant %s', [$propertyName, $nodeVariant->getContextPath()])); $this->skip(function () use ($nodeVariant, $propertyName, $newValue) { $nodeVariant->setProperty($propertyName, $newValue); }); - }, $node->getOtherNodeVariants()); + }, $this->getOtherNodeVariants($node, $currentDimensions)); + } public function skip(\Closure $closure) @@ -65,4 +73,30 @@ protected function managedProperties(NodeInterface $node, $propertyName) $configuration = $node->getNodeType()->getConfiguration(self::CONFIGURATION_PATH) ?: []; return isset($configuration[$propertyName]) && $configuration[$propertyName] === true; } + + private function getOtherNodeVariants(NodeInterface $node, $currentDimensions) + { + $nodeVariants = []; + + foreach ($this->dimensionCombinator->getAllAllowedCombinations() as $dimensionCombination) { + + // Remove fallback dimension values + $dimensions = array_map(fn($dimensionValues) => [reset($dimensionValues)], $dimensionCombination); + + if ($dimensions === $currentDimensions) { + continue; + } + + $context = $node->getContext()->getProperties(); + $context['dimensions'] = $dimensions; + unset($context['targetDimensions']); + + $nodeVariant = $this->contextFactory->create($context)->getNodeByIdentifier((string)$node->getNodeAggregateIdentifier()); + if ($nodeVariant) { + $nodeVariants[] = $nodeVariant; + } + } + + return $nodeVariants; + } }