From b6673a770b67d484717248ff2455d6635a0e8bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mu=CC=88ller?= Date: Wed, 23 Oct 2024 12:32:22 +0200 Subject: [PATCH] Update to latest references commits --- Classes/Domain/Model/Changes/Property.php | 2 +- .../NodeCreation/NodeCreationCommands.php | 9 ++++++++ ...PromotedElementsCreationHandlerFactory.php | 23 ++++++++----------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Classes/Domain/Model/Changes/Property.php b/Classes/Domain/Model/Changes/Property.php index 5a5ca3748f..93ece455dc 100644 --- a/Classes/Domain/Model/Changes/Property.php +++ b/Classes/Domain/Model/Changes/Property.php @@ -239,7 +239,7 @@ private function handleNodeReferenceChange(Node $subject, string $propertyName): $subject->workspaceName, $subject->aggregateId, $subject->originDimensionSpacePoint, - NodeReferencesToWrite::fromReferenceNameAndNodeAggregateIds(ReferenceName::fromString($propertyName), NodeAggregateIds::fromArray($destinationNodeAggregateIds)) + NodeReferencesToWrite::fromNameAndTargets(ReferenceName::fromString($propertyName), NodeAggregateIds::fromArray($destinationNodeAggregateIds)) ) ); } diff --git a/Classes/Domain/NodeCreation/NodeCreationCommands.php b/Classes/Domain/NodeCreation/NodeCreationCommands.php index ad225e5fcb..52115aad6e 100644 --- a/Classes/Domain/NodeCreation/NodeCreationCommands.php +++ b/Classes/Domain/NodeCreation/NodeCreationCommands.php @@ -21,6 +21,7 @@ use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties; use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite; use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences; +use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesToWrite; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; /** @@ -107,6 +108,14 @@ public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPrope ); } + public function withInitialReferences(NodeReferencesToWrite $newInitialReferences): self + { + return new self( + $this->first->withReferences($newInitialReferences), + ...$this->additionalCommands + ); + } + public function withAdditionalCommands( CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences|CopyNodesRecursively ...$additionalCommands ): self { diff --git a/Classes/Infrastructure/ContentRepository/CreationDialog/PromotedElementsCreationHandlerFactory.php b/Classes/Infrastructure/ContentRepository/CreationDialog/PromotedElementsCreationHandlerFactory.php index f20cbf5818..996f4f3619 100644 --- a/Classes/Infrastructure/ContentRepository/CreationDialog/PromotedElementsCreationHandlerFactory.php +++ b/Classes/Infrastructure/ContentRepository/CreationDialog/PromotedElementsCreationHandlerFactory.php @@ -5,7 +5,6 @@ namespace Neos\Neos\Ui\Infrastructure\ContentRepository\CreationDialog; use Neos\ContentRepository\Core\ContentRepository; -use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences; use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesToWrite; use Neos\ContentRepository\Core\NodeType\NodeTypeManager; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds; @@ -39,7 +38,7 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele return $commands; } $propertyValues = $commands->first->initialPropertyValues; - $setReferencesCommands = []; + $initialReferences = null; foreach ($elements as $elementName => $elementValue) { // handle properties if ($nodeType->hasProperty($elementName)) { @@ -56,23 +55,19 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele if ($nodeType->hasReference($elementName)) { assert($elementValue instanceof NodeAggregateIds); $referenceConfiguration = $nodeType->getReferences()[$elementName]; - if ( - ($referenceConfiguration['ui']['showInCreationDialog'] ?? false) === true - ) { - // a promoted element - $setReferencesCommands[] = SetNodeReferences::create( - $commands->first->workspaceName, - $commands->first->nodeAggregateId, - $commands->first->originDimensionSpacePoint, - NodeReferencesToWrite::fromReferenceNameAndNodeAggregateIds(ReferenceName::fromString($elementName), $elementValue) - ); + if (($referenceConfiguration['ui']['showInCreationDialog'] ?? false) === true) { + $referencesToWriteForCurrentElement = NodeReferencesToWrite::fromNameAndTargets(ReferenceName::fromString($elementName), $elementValue); + $initialReferences = $initialReferences === null ? $referencesToWriteForCurrentElement : $initialReferences->merge($referencesToWriteForCurrentElement); } } } + if ($initialReferences !== null) { + $commands = $commands->withInitialReferences($initialReferences); + } + return $commands - ->withInitialPropertyValues($propertyValues) - ->withAdditionalCommands(...$setReferencesCommands); + ->withInitialPropertyValues($propertyValues); } }; }