Skip to content

Commit

Permalink
BUGFIX: Add workaround for unsetting properties with default values
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 21, 2024
1 parent 5f3b21b commit 4d1ccfa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 19 additions & 5 deletions Classes/Domain/NodeCreation/NodeCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;
Expand Down Expand Up @@ -73,13 +74,26 @@ public function apply(RootTemplate $template, NodeCreationCommands $commands, No
$template->getProperties()
);

$propertyValuesToWrite = PropertyValuesToWrite::fromArray(
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
);

if (count($defaultPropertiesToUnset = iterator_to_array($propertyValuesToWrite->getPropertiesToUnset()))) {
// FIXME workaround for https://github.com/neos/neos-development-collection/issues/5154
$setDefaultPropertiesToNull = SetNodeProperties::create(
$commands->first->workspaceName,
$commands->first->nodeAggregateId,
$commands->first->originDimensionSpacePoint,
PropertyValuesToWrite::fromArray(
array_fill_keys(array_map(fn (PropertyName $name) => $name->value, $defaultPropertiesToUnset), null)
)
);
$commands = $commands->withAdditionalCommands($setDefaultPropertiesToNull);
}

$initialProperties = $commands->first->initialPropertyValues;

$initialProperties = $initialProperties->merge(
PropertyValuesToWrite::fromArray(
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
)
);
$initialProperties = $initialProperties->merge($propertyValuesToWrite);

$initialProperties = $this->ensureNodeHasUriPathSegment(
$nodeType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"properties": {
"unsetValueWithDefault": null,
"someValueWithDefault": true,
"text": "abc",
"isEnchanted": false,
"selectBox": "karma",
"nullValue": null
"selectBox": "karma"
},
"references": {
"reference": [
Expand Down

0 comments on commit 4d1ccfa

Please sign in to comment.