77use Flowpack \NodeTemplates \Domain \Template \RootTemplate ;
88use Flowpack \NodeTemplates \Domain \Template \Template ;
99use Flowpack \NodeTemplates \Domain \Template \Templates ;
10- use Neos \ContentRepository \Core \ContentRepository ;
10+ use Neos \ContentRepository \Core \DimensionSpace \ OriginDimensionSpacePoint ;
1111use Neos \ContentRepository \Core \Feature \NodeCreation \Command \CreateNodeAggregateWithNode ;
1212use Neos \ContentRepository \Core \Feature \NodeModification \Command \SetNodeProperties ;
13+ use Neos \ContentRepository \Core \Feature \NodeModification \Dto \PropertyValuesToWrite ;
14+ use Neos \ContentRepository \Core \Feature \NodeReferencing \Command \SetNodeReferences ;
15+ use Neos \ContentRepository \Core \Feature \NodeReferencing \Dto \NodeReferencesToWrite ;
1316use Neos \ContentRepository \Core \NodeType \NodeTypeManager ;
17+ use Neos \ContentRepository \Core \Projection \ContentGraph \ContentSubgraphInterface ;
1418use Neos \ContentRepository \Core \SharedModel \Node \NodeAggregateId ;
19+ use Neos \ContentRepository \Core \SharedModel \Node \NodeAggregateIds ;
1520use Neos \ContentRepository \Core \SharedModel \Node \NodeName ;
21+ use Neos \ContentRepository \Core \SharedModel \Node \ReferenceName ;
22+ use Neos \ContentRepository \Core \SharedModel \Workspace \ContentStreamId ;
1623use Neos \Flow \Annotations as Flow ;
1724use Neos \Neos \Ui \NodeCreationHandler \NodeCreationCommands ;
1825use Neos \Neos \Utility \NodeUriPathSegmentGenerator ;
@@ -26,7 +33,7 @@ class NodeCreationService
2633 protected $ nodeUriPathSegmentGenerator ;
2734
2835 public function __construct (
29- private readonly ContentRepository $ contentRepository ,
36+ private readonly ContentSubgraphInterface $ subgraph ,
3037 private readonly NodeTypeManager $ nodeTypeManager
3138 ) {
3239 }
@@ -45,14 +52,9 @@ public function apply(RootTemplate $template, NodeCreationCommands $commands, Ca
4552 $ initialProperties = $ commands ->initialCreateCommand ->initialPropertyValues ;
4653
4754 $ initialProperties = $ initialProperties ->merge (
48- $ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions )
55+ PropertyValuesToWrite:: fromArray ( $ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions) )
4956 );
5057
51- // todo set references
52- // foreach ($propertiesAndReferences->requireValidReferences($nodeType, $commands->getContext(), $caughtExceptions) as $key => $value) {
53- // $commands->setProperty($key, $value);
54- // }
55-
5658 // $this->ensureNodeHasUriPathSegment($commands, $template);
5759 return $ this ->applyTemplateRecursively (
5860 $ template ->getChildNodes (),
@@ -62,7 +64,14 @@ public function apply(RootTemplate $template, NodeCreationCommands $commands, Ca
6264 $ commands ->initialCreateCommand ->nodeAggregateId ,
6365 $ nodeType ,
6466 ),
65- $ commands ->withInitialPropertyValues ($ initialProperties ),
67+ $ commands ->withInitialPropertyValues ($ initialProperties )->withAdditionalCommands (
68+ ...$ this ->createReferencesCommands (
69+ $ commands ->initialCreateCommand ->contentStreamId ,
70+ $ commands ->initialCreateCommand ->nodeAggregateId ,
71+ $ commands ->initialCreateCommand ->originDimensionSpacePoint ,
72+ $ propertiesAndReferences ->requireValidReferences ($ nodeType , $ this ->subgraph , $ caughtExceptions )
73+ )
74+ ),
6675 $ caughtExceptions
6776 );
6877 }
@@ -89,12 +98,16 @@ private function applyTemplateRecursively(Templates $templates, ToBeCreatedNode
8998 $ template ->getName ()
9099 ),
91100 $ parentNode ->originDimensionSpacePoint ,
92- $ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions )
101+ PropertyValuesToWrite::fromArray ($ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions ))
102+ ),
103+ ...$ this ->createReferencesCommands (
104+ $ parentNode ->contentStreamId ,
105+ $ nodeAggregateId ,
106+ $ parentNode ->originDimensionSpacePoint ,
107+ $ propertiesAndReferences ->requireValidReferences ($ nodeType , $ this ->subgraph , $ caughtExceptions )
93108 )
94109 );
95110
96- // todo references
97-
98111 $ commands = $ this ->applyTemplateRecursively (
99112 $ template ->getChildNodes (),
100113 $ parentNode ->withNodeTypeAndNodeAggregateId (
@@ -104,7 +117,6 @@ private function applyTemplateRecursively(Templates $templates, ToBeCreatedNode
104117 $ commands ,
105118 $ caughtExceptions
106119 );
107-
108120 continue ;
109121 }
110122
@@ -125,11 +137,8 @@ private function applyTemplateRecursively(Templates $templates, ToBeCreatedNode
125137
126138 $ nodeType = $ this ->nodeTypeManager ->getNodeType ($ template ->getType ());
127139
128-
129140 $ propertiesAndReferences = PropertiesAndReferences::createFromArrayAndTypeDeclarations ($ template ->getProperties (), $ nodeType );
130141
131- // hande references
132-
133142 $ commands = $ commands ->withAdditionalCommands (
134143 new CreateNodeAggregateWithNode (
135144 $ parentNode ->contentStreamId ,
@@ -138,14 +147,16 @@ private function applyTemplateRecursively(Templates $templates, ToBeCreatedNode
138147 $ parentNode ->originDimensionSpacePoint ,
139148 $ parentNode ->nodeAggregateId ,
140149 nodeName: NodeName::fromString (uniqid ('node- ' , false )),
141- initialPropertyValues: $ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions )
150+ initialPropertyValues: PropertyValuesToWrite::fromArray ($ propertiesAndReferences ->requireValidProperties ($ nodeType , $ caughtExceptions ))
151+ ),
152+ ...$ this ->createReferencesCommands (
153+ $ parentNode ->contentStreamId ,
154+ $ nodeAggregateId ,
155+ $ parentNode ->originDimensionSpacePoint ,
156+ $ propertiesAndReferences ->requireValidReferences ($ nodeType , $ this ->subgraph , $ caughtExceptions )
142157 )
143158 );
144159
145- // set references
146- // foreach ($propertiesAndReferences->requireValidReferences($nodeType, $node->getContext(), $caughtExceptions) as $key => $value) {
147- // $node->setProperty($key, $value);
148- // }
149160
150161 // $this->ensureNodeHasUriPathSegment($node, $template);
151162 $ commands = $ this ->applyTemplateRecursively (
@@ -162,6 +173,25 @@ private function applyTemplateRecursively(Templates $templates, ToBeCreatedNode
162173 return $ commands ;
163174 }
164175
176+ /**
177+ * @param array<string, NodeAggregateIds> $references
178+ * @return list<SetNodeReferences>
179+ */
180+ private function createReferencesCommands (ContentStreamId $ contentStreamId , NodeAggregateId $ nodeAggregateId , OriginDimensionSpacePoint $ originDimensionSpacePoint , array $ references ): array
181+ {
182+ $ commands = [];
183+ foreach ($ references as $ name => $ nodeAggregateIds ) {
184+ $ commands [] = new SetNodeReferences (
185+ $ contentStreamId ,
186+ $ nodeAggregateId ,
187+ $ originDimensionSpacePoint ,
188+ ReferenceName::fromString ($ name ),
189+ NodeReferencesToWrite::fromNodeAggregateIds ($ nodeAggregateIds )
190+ );
191+ }
192+ return $ commands ;
193+ }
194+
165195 /**
166196 * All document node types get a uri path segment; if it is not explicitly set in the properties,
167197 * it should be built based on the title property
0 commit comments