diff --git a/Classes/Domain/Model/Changes/AbstractCreate.php b/Classes/Domain/Model/Changes/AbstractCreate.php index ab492ace70..159942f029 100644 --- a/Classes/Domain/Model/Changes/AbstractCreate.php +++ b/Classes/Domain/Model/Changes/AbstractCreate.php @@ -115,7 +115,9 @@ protected function createNode( $contentRepository = $this->contentRepositoryRegistry->get($parentNode->subgraphIdentity->contentRepositoryId); $commands = $this->applyNodeCreationHandlers( - new NodeCreationCommands($command), + NodeCreationCommands::fromFirstCommand( + $command + ), $nodeTypeName, $contentRepository ); diff --git a/Classes/NodeCreationHandler/NodeCreationCommands.php b/Classes/NodeCreationHandler/NodeCreationCommands.php index 2c502ebc77..d68080520c 100644 --- a/Classes/NodeCreationHandler/NodeCreationCommands.php +++ b/Classes/NodeCreationHandler/NodeCreationCommands.php @@ -16,6 +16,7 @@ use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode; use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\DisableNodeAggregate; use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\EnableNodeAggregate; +use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively; use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties; use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite; use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences; @@ -29,36 +30,53 @@ * * All commands will be executed blocking. * - * @api except the constructor + * You can retrieve the subgraph or the parent node (where the first node will be created in) the following way: + * + * $subgraph = $contentRepository->getContentGraph()->getSubgraph( + * $commands->first->contentStreamId, + * $commands->first->originDimensionSpacePoint->toDimensionSpacePoint(), + * VisibilityConstraints::frontend() + * ); + * $parentNode = $subgraph->findNodeById($commands->first->parentNodeAggregateId); + * + * @api Note: The constructor and {@see self::fromFirstCommand} are not part of the public API */ -class NodeCreationCommands implements \IteratorAggregate +final readonly class NodeCreationCommands implements \IteratorAggregate { /** * The initial node creation command. * It is only allowed to change its properties via {@see self::withInitialPropertyValues()} */ - public readonly CreateNodeAggregateWithNode $first; + public CreateNodeAggregateWithNode $first; /** * Add a list of commands that are executed after the initial created command was run. * This allows to create child-nodes and append other allowed commands. * - * @var array + * @var array */ - public readonly array $additionalCommands; + public array $additionalCommands; - /** - * @internal to guarantee that the initial create command is mostly preserved as intended. - * You can use {@see self::withInitialPropertyValues()} to add new properties of the to be created node. - */ - public function __construct( + private function __construct( CreateNodeAggregateWithNode $first, - CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences ...$additionalCommands + CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences|CopyNodesRecursively ...$additionalCommands ) { $this->first = $first; $this->additionalCommands = $additionalCommands; } + /** + * @internal to guarantee that the initial create command is mostly preserved as intended. + * You can use {@see self::withInitialPropertyValues()} to add new properties of the to be created node. + */ + public static function fromFirstCommand( + CreateNodeAggregateWithNode $firstCreateNodeAggregateWithNodeCommand, + ): self { + return new self( + $firstCreateNodeAggregateWithNodeCommand, + ); + } + /** * Augment the first {@see CreateNodeAggregateWithNode} command with altered properties. */ @@ -71,7 +89,7 @@ public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPrope } public function withAdditionalCommands( - CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences ...$additionalCommands + CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences|CopyNodesRecursively ...$additionalCommands ): self { return new self($this->first, ...$this->additionalCommands, ...$additionalCommands); }