Skip to content

Commit

Permalink
BUGFIX: Reference support in NodeCreationHandler
Browse files Browse the repository at this point in the history
Resolves: #3615
  • Loading branch information
mhsdesign committed Feb 28, 2024
1 parent c1a73e3 commit 4ff1532
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
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\ReferenceName;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationCommands;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationElements;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerInterface;
Expand All @@ -31,8 +34,10 @@ public function __construct(
public function handle(NodeCreationCommands $commands, NodeCreationElements $elements): NodeCreationCommands
{
$nodeType = $this->nodeTypeManager->getNodeType($commands->first->nodeTypeName);

// handle properties
$propertyValues = $commands->first->initialPropertyValues;
foreach ($nodeType->getConfiguration('properties') as $propertyName => $propertyConfiguration) {
foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) {
if (
!isset($propertyConfiguration['ui']['showInCreationDialog'])
|| $propertyConfiguration['ui']['showInCreationDialog'] !== true
Expand All @@ -43,11 +48,39 @@ public function handle(NodeCreationCommands $commands, NodeCreationElements $ele
if (!$elements->hasPropertyLike($propertyName)) {
continue;
}
// todo support also references https://github.com/neos/neos-ui/issues/3615
$propertyValues = $propertyValues->withValue($propertyName, $elements->getPropertyLike($propertyName));
}

return $commands->withInitialPropertyValues($propertyValues);
// handle references
$setReferencesCommands = [];
foreach ($nodeType->getProperties() as $referenceName => $referenceConfiguration) {
// todo this will be replaced by $nodeType->getReferences()
if ($nodeType->getPropertyType($referenceName) !== 'references' && $nodeType->getPropertyType($referenceName) !== 'reference') {
continue; // no a reference
}
if (
!isset($referenceConfiguration['ui']['showInCreationDialog'])
|| $referenceConfiguration['ui']['showInCreationDialog'] !== true
) {
// not a promoted reference
continue;
}
if (!$elements->hasReferenceLike($referenceName)) {
continue;
}

$setReferencesCommands[] = SetNodeReferences::create(
$commands->first->contentStreamId,
$commands->first->nodeAggregateId,
$commands->first->originDimensionSpacePoint,
ReferenceName::fromString($referenceName),
NodeReferencesToWrite::fromNodeAggregateIds($elements->getReferenceLike($referenceName))
);
}

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

0 comments on commit 4ff1532

Please sign in to comment.