Skip to content

Commit

Permalink
Update to latest references commits
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Oct 23, 2024
1 parent 9e7a7cd commit b6673a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Changes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function handleNodeReferenceChange(Node $subject, string $propertyName):
$subject->workspaceName,
$subject->aggregateId,
$subject->originDimensionSpacePoint,
NodeReferencesToWrite::fromReferenceNameAndNodeAggregateIds(ReferenceName::fromString($propertyName), NodeAggregateIds::fromArray($destinationNodeAggregateIds))
NodeReferencesToWrite::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,7 +5,6 @@
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\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
Expand Down Expand Up @@ -39,7 +38,7 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele
return $commands;
}
$propertyValues = $commands->first->initialPropertyValues;
$setReferencesCommands = [];
$initialReferences = null;
foreach ($elements as $elementName => $elementValue) {
// handle properties
if ($nodeType->hasProperty($elementName)) {
Expand All @@ -56,23 +55,19 @@ 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,
NodeReferencesToWrite::fromReferenceNameAndNodeAggregateIds(ReferenceName::fromString($elementName), $elementValue)
);
if (($referenceConfiguration['ui']['showInCreationDialog'] ?? false) === true) {
$referencesToWriteForCurrentElement = NodeReferencesToWrite::fromNameAndTargets(ReferenceName::fromString($elementName), $elementValue);
$initialReferences = $initialReferences === null ? $referencesToWriteForCurrentElement : $initialReferences->merge($referencesToWriteForCurrentElement);
}
}
}

if ($initialReferences !== null) {
$commands = $commands->withInitialReferences($initialReferences);
}

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

0 comments on commit b6673a7

Please sign in to comment.