Skip to content

Commit

Permalink
Merge pull request #3876 from pKallert/feature/automatically-set-node…
Browse files Browse the repository at this point in the history
…move-strategy

FEATURE: Automatically set nodemove strategy in core
  • Loading branch information
kitsunet authored Nov 27, 2024
2 parents 79e7c3e + 3c03e53 commit 4e3824a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 9 additions & 3 deletions Classes/Domain/Model/Changes/MoveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ public function apply(): void
$hasEqualParentNode = $parentNode->aggregateId
->equals($parentNodeOfPreviousSibling->aggregateId);


$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);

$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$command = MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
RelationDistributionStrategy::STRATEGY_GATHER_ALL,
$moveNodeStrategy,
$hasEqualParentNode ? null : $parentNodeOfPreviousSibling->aggregateId,
$precedingSibling->aggregateId,
$succeedingSibling?->aggregateId,
Expand Down
11 changes: 9 additions & 2 deletions Classes/Domain/Model/Changes/MoveBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,20 @@ public function apply(): void
->equals($succeedingSiblingParent->aggregateId);

$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);

$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$contentRepository->handle(
MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
RelationDistributionStrategy::STRATEGY_GATHER_ALL,
$moveNodeStrategy,
$hasEqualParentNode
? null
: $succeedingSiblingParent->aggregateId,
Expand Down
10 changes: 9 additions & 1 deletion Classes/Domain/Model/Changes/MoveInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ public function apply(): void
->equals($parentNode->aggregateId);

$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$contentRepository->handle(
MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
RelationDistributionStrategy::STRATEGY_GATHER_ALL,
$moveNodeStrategy,
$hasEqualParentNode ? null : $parentNode->aggregateId,
)
);
Expand Down
2 changes: 2 additions & 0 deletions Configuration/NodeTypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
factoryClassName: 'Neos\Neos\Ui\Infrastructure\Neos\UriPathSegmentNodeCreationHandlerFactory'
promotedElements:
factoryClassName: 'Neos\Neos\Ui\Infrastructure\ContentRepository\CreationDialog\PromotedElementsCreationHandlerFactory'
moveNodeStrategy: gatherAll

'Neos.Neos:Content':
postprocessors:
Expand All @@ -34,6 +35,7 @@
nodeCreationHandlers:
promotedElements:
factoryClassName: 'Neos\Neos\Ui\Infrastructure\ContentRepository\CreationDialog\PromotedElementsCreationHandlerFactory'
moveNodeStrategy: scatter

'Neos.Neos:ContentCollection':
ui:
Expand Down

0 comments on commit 4e3824a

Please sign in to comment.