Skip to content

Commit

Permalink
Adjust to Neos9 Beta15
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Nov 11, 2024
1 parent f35a583 commit 67abdde
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
83 changes: 49 additions & 34 deletions Classes/Domain/NodeCreation/NodeCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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\NodeReferencesForName;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesToWrite;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
Expand Down Expand Up @@ -102,17 +103,21 @@ public function apply(RootTemplate $template, NodeCreationCommands $commands, No
$initialProperties
);

$commands = $commands->withInitialPropertyValues($initialProperties);
$setReferences = $this->createReferencesCommand(
$commands->first->workspaceName,
$commands->first->nodeAggregateId,
$commands->first->originDimensionSpacePoint,
$this->referencesProcessor->processAndValidateReferences($node, $processingErrors)
);
if ($setReferences) {
$commands = $commands->withAdditionalCommands($setReferences);
}

return $this->applyTemplateRecursively(
$template->getChildNodes(),
$node,
$commands->withInitialPropertyValues($initialProperties)->withAdditionalCommands(
...$this->createReferencesCommands(
$commands->first->workspaceName,
$commands->first->nodeAggregateId,
$commands->first->originDimensionSpacePoint,
$this->referencesProcessor->processAndValidateReferences($node, $processingErrors)
)
),
$commands,
$processingErrors
);
}
Expand All @@ -136,7 +141,7 @@ private function applyTemplateRecursively(Templates $templates, TransientNode $p
$template->getProperties()
);

$commands = $commands->withAdditionalCommands(
$commands = $commands->withAdditionalCommands(...array_filter([
SetNodeProperties::create(
$parentNode->workspaceName,
$node->aggregateId,
Expand All @@ -145,13 +150,13 @@ private function applyTemplateRecursively(Templates $templates, TransientNode $p
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
)
),
...$this->createReferencesCommands(
$this->createReferencesCommand(
$parentNode->workspaceName,
$node->aggregateId,
$parentNode->originDimensionSpacePoint,
$this->referencesProcessor->processAndValidateReferences($node, $processingErrors)
)
);
]));

$commands = $this->applyTemplateRecursively(
$template->getChildNodes(),
Expand Down Expand Up @@ -198,7 +203,7 @@ private function applyTemplateRecursively(Templates $templates, TransientNode $p

$node = $parentNode->forRegularChildNode(NodeAggregateId::create(), $nodeType, $template->getProperties());

$nodeName = $template->getName() ?? NodeName::fromString(uniqid('node-', false));
$nodeName = $template->getName();

$initialProperties = PropertyValuesToWrite::fromArray(
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
Expand All @@ -211,24 +216,27 @@ private function applyTemplateRecursively(Templates $templates, TransientNode $p
$initialProperties
);

$commands = $commands->withAdditionalCommands(
CreateNodeAggregateWithNode::create(
$parentNode->workspaceName,
$node->aggregateId,
$template->getType(),
$parentNode->originDimensionSpacePoint,
$parentNode->aggregateId,
nodeName: $nodeName,
initialPropertyValues: $initialProperties
)->withTetheredDescendantNodeAggregateIds($node->tetheredNodeAggregateIds),
...$this->createReferencesCommands(
$createNode = CreateNodeAggregateWithNode::create(
$parentNode->workspaceName,
$node->aggregateId,
$template->getType(),
$parentNode->originDimensionSpacePoint,
$parentNode->aggregateId,
initialPropertyValues: $initialProperties
)->withTetheredDescendantNodeAggregateIds($node->tetheredNodeAggregateIds);
if ($nodeName) {
$createNode = $createNode->withNodeName($nodeName);
}

$commands = $commands->withAdditionalCommands(...array_filter([
$createNode,
$this->createReferencesCommand(
$parentNode->workspaceName,
$node->aggregateId,
$parentNode->originDimensionSpacePoint,
$this->referencesProcessor->processAndValidateReferences($node, $processingErrors)
)
);

]));

$commands = $this->applyTemplateRecursively(
$template->getChildNodes(),
Expand All @@ -243,21 +251,28 @@ private function applyTemplateRecursively(Templates $templates, TransientNode $p

/**
* @param array<string, NodeAggregateIds> $references
* @return list<SetNodeReferences>
*/
private function createReferencesCommands(WorkspaceName $workspaceName, NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, array $references): array
{
$commands = [];
private function createReferencesCommand(
WorkspaceName $workspaceName,
NodeAggregateId $nodeAggregateId,
OriginDimensionSpacePoint $originDimensionSpacePoint,
array $references
): ?SetNodeReferences {
$referencesForName = [];
foreach ($references as $name => $nodeAggregateIds) {
$commands[] = SetNodeReferences::create(
$referencesForName[] = NodeReferencesForName::fromTargets(
ReferenceName::fromString($name),
$nodeAggregateIds,
);
}
return empty($referencesForName)
? null
: SetNodeReferences::create(
$workspaceName,
$nodeAggregateId,
$originDimensionSpacePoint,
ReferenceName::fromString($name),
NodeReferencesToWrite::fromNodeAggregateIds($nodeAggregateIds)
NodeReferencesToWrite::create(...$referencesForName)
);
}
return $commands;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions Tests/Unit/NodeMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Symfony\Component\Serializer\Serializer;

Expand All @@ -40,8 +39,6 @@ private function createNodeMock(NodeAggregateId $nodeAggregateId = null): Node
NodeTags::createEmpty(),
Timestamps::create($now = new \DateTimeImmutable(), $now, null, null),
VisibilityConstraints::withoutRestrictions(),
null,
ContentStreamId::fromString("cs")
);
}
}

0 comments on commit 67abdde

Please sign in to comment.