From 4ff1532f1dc17cb941e281fd5f7138ceb3bd19d5 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:01:24 +0100 Subject: [PATCH] BUGFIX: Reference support in NodeCreationHandler Resolves: https://github.com/neos/neos-ui/issues/3615 --- ...PromotedElementsCreationHandlerFactory.php | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Classes/Infrastructure/NodeCreation/PromotedElementsCreationHandlerFactory.php b/Classes/Infrastructure/NodeCreation/PromotedElementsCreationHandlerFactory.php index aa8760c455..d050d8d00b 100644 --- a/Classes/Infrastructure/NodeCreation/PromotedElementsCreationHandlerFactory.php +++ b/Classes/Infrastructure/NodeCreation/PromotedElementsCreationHandlerFactory.php @@ -6,7 +6,10 @@ use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies; use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface; +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\ReferenceName; use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationCommands; use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationElements; use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerInterface; @@ -31,8 +34,10 @@ public function __construct( public function handle(NodeCreationCommands $commands, NodeCreationElements $elements): NodeCreationCommands { $nodeType = $this->nodeTypeManager->getNodeType($commands->first->nodeTypeName); + + // handle properties $propertyValues = $commands->first->initialPropertyValues; - foreach ($nodeType->getConfiguration('properties') as $propertyName => $propertyConfiguration) { + foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) { if ( !isset($propertyConfiguration['ui']['showInCreationDialog']) || $propertyConfiguration['ui']['showInCreationDialog'] !== true @@ -43,11 +48,39 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele if (!$elements->hasPropertyLike($propertyName)) { continue; } - // todo support also references https://github.com/neos/neos-ui/issues/3615 $propertyValues = $propertyValues->withValue($propertyName, $elements->getPropertyLike($propertyName)); } - return $commands->withInitialPropertyValues($propertyValues); + // handle references + $setReferencesCommands = []; + foreach ($nodeType->getProperties() as $referenceName => $referenceConfiguration) { + // todo this will be replaced by $nodeType->getReferences() + if ($nodeType->getPropertyType($referenceName) !== 'references' && $nodeType->getPropertyType($referenceName) !== 'reference') { + continue; // no a reference + } + if ( + !isset($referenceConfiguration['ui']['showInCreationDialog']) + || $referenceConfiguration['ui']['showInCreationDialog'] !== true + ) { + // not a promoted reference + continue; + } + if (!$elements->hasReferenceLike($referenceName)) { + continue; + } + + $setReferencesCommands[] = SetNodeReferences::create( + $commands->first->contentStreamId, + $commands->first->nodeAggregateId, + $commands->first->originDimensionSpacePoint, + ReferenceName::fromString($referenceName), + NodeReferencesToWrite::fromNodeAggregateIds($elements->getReferenceLike($referenceName)) + ); + } + + return $commands + ->withInitialPropertyValues($propertyValues) + ->withAdditionalCommands(...$setReferencesCommands); } }; }