Skip to content

Commit

Permalink
Merge pull request #3844 from neos/bugfix/references-on-copy
Browse files Browse the repository at this point in the history
Adjustments to new Reference DTOs
  • Loading branch information
mhsdesign authored Nov 1, 2024
2 parents 147a733 + 874e187 commit b810deb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
9 changes: 7 additions & 2 deletions Classes/Domain/Model/Changes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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\Feature\NodeTypeChange\Command\ChangeNodeAggregateType;
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Dto\NodeAggregateTypeChangeChildConstraintConflictResolutionStrategy;
Expand Down Expand Up @@ -239,8 +240,12 @@ private function handleNodeReferenceChange(Node $subject, string $propertyName):
$subject->workspaceName,
$subject->aggregateId,
$subject->originDimensionSpacePoint,
ReferenceName::fromString($propertyName),
NodeReferencesToWrite::fromNodeAggregateIds(NodeAggregateIds::fromArray($destinationNodeAggregateIds))
NodeReferencesToWrite::fromReferences(
NodeReferencesForName::fromNameAndTargets(
ReferenceName::fromString($propertyName),
NodeAggregateIds::fromArray($destinationNodeAggregateIds)
)
)
)
);
}
Expand Down
9 changes: 9 additions & 0 deletions Classes/Domain/NodeCreation/NodeCreationCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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\NodeReferencesToWrite;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;

/**
Expand Down Expand Up @@ -107,6 +108,14 @@ public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPrope
);
}

public function withInitialReferences(NodeReferencesToWrite $newInitialReferences): self
{
return new self(
$this->first->withReferences($newInitialReferences),
...$this->additionalCommands
);
}

public function withAdditionalCommands(
CreateNodeAggregateWithNode|SetNodeProperties|DisableNodeAggregate|EnableNodeAggregate|SetNodeReferences|CopyNodesRecursively ...$additionalCommands
): self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
namespace Neos\Neos\Ui\Infrastructure\ContentRepository\CreationDialog;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesToWrite;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\NodeReferencesForName;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
Expand Down Expand Up @@ -39,7 +38,7 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele
return $commands;
}
$propertyValues = $commands->first->initialPropertyValues;
$setReferencesCommands = [];
$initialReferences = $commands->first->references;
foreach ($elements as $elementName => $elementValue) {
// handle properties
if ($nodeType->hasProperty($elementName)) {
Expand All @@ -56,24 +55,20 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele
if ($nodeType->hasReference($elementName)) {
assert($elementValue instanceof NodeAggregateIds);
$referenceConfiguration = $nodeType->getReferences()[$elementName];
if (
($referenceConfiguration['ui']['showInCreationDialog'] ?? false) === true
) {
// a promoted element
$setReferencesCommands[] = SetNodeReferences::create(
$commands->first->workspaceName,
$commands->first->nodeAggregateId,
$commands->first->originDimensionSpacePoint,
ReferenceName::fromString($elementName),
NodeReferencesToWrite::fromNodeAggregateIds($elementValue)
if (($referenceConfiguration['ui']['showInCreationDialog'] ?? false) === true) {
$initialReferences = $initialReferences->withReference(
NodeReferencesForName::fromNameAndTargets(
ReferenceName::fromString($elementName),
$elementValue
)
);
}
}
}

return $commands
->withInitialPropertyValues($propertyValues)
->withAdditionalCommands(...$setReferencesCommands);
->withInitialReferences($initialReferences);
}
};
}
Expand Down

0 comments on commit b810deb

Please sign in to comment.