Skip to content

Commit f9fbf3f

Browse files
committed
BUGFIX: Reference support in NodeCreationHandler
Resolves: #3615
1 parent 0b8cfb4 commit f9fbf3f

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

Classes/Infrastructure/NodeCreation/PromotedElementsCreationHandlerFactory.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
88
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
9+
use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences;
10+
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesToWrite;
911
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
12+
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
1013
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationCommands;
1114
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationElements;
1215
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerInterface;
@@ -31,8 +34,10 @@ public function __construct(
3134
public function handle(NodeCreationCommands $commands, NodeCreationElements $elements): NodeCreationCommands
3235
{
3336
$nodeType = $this->nodeTypeManager->getNodeType($commands->first->nodeTypeName);
37+
38+
// handle properties
3439
$propertyValues = $commands->first->initialPropertyValues;
35-
foreach ($nodeType->getConfiguration('properties') as $propertyName => $propertyConfiguration) {
40+
foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) {
3641
if (
3742
!isset($propertyConfiguration['ui']['showInCreationDialog'])
3843
|| $propertyConfiguration['ui']['showInCreationDialog'] !== true
@@ -43,11 +48,39 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele
4348
if (!$elements->hasPropertyLike($propertyName)) {
4449
continue;
4550
}
46-
// todo support also references https://github.com/neos/neos-ui/issues/3615
4751
$propertyValues = $propertyValues->withValue($propertyName, $elements->getPropertyLike($propertyName));
4852
}
4953

50-
return $commands->withInitialPropertyValues($propertyValues);
54+
// handle references
55+
$setReferencesCommands = [];
56+
foreach ($nodeType->getProperties() as $referenceName => $referenceConfiguration) {
57+
// todo this will be replaced by $nodeType->getReferences()
58+
if ($nodeType->getPropertyType($referenceName) !== 'references' && $nodeType->getPropertyType($referenceName) !== 'reference') {
59+
continue; // no a reference
60+
}
61+
if (
62+
!isset($referenceConfiguration['ui']['showInCreationDialog'])
63+
|| $referenceConfiguration['ui']['showInCreationDialog'] !== true
64+
) {
65+
// not a promoted reference
66+
continue;
67+
}
68+
if (!$elements->hasReferenceLike($referenceName)) {
69+
continue;
70+
}
71+
72+
$setReferencesCommands[] = SetNodeReferences::create(
73+
$commands->first->contentStreamId,
74+
$commands->first->nodeAggregateId,
75+
$commands->first->originDimensionSpacePoint,
76+
ReferenceName::fromString($referenceName),
77+
NodeReferencesToWrite::fromNodeAggregateIds($elements->getReferenceLike($referenceName))
78+
);
79+
}
80+
81+
return $commands
82+
->withInitialPropertyValues($propertyValues)
83+
->withAdditionalCommands(...$setReferencesCommands);
5184
}
5285
};
5386
}

0 commit comments

Comments
 (0)