Skip to content

Commit 4d1ccfa

Browse files
committed
BUGFIX: Add workaround for unsetting properties with default values
See neos/neos-development-collection#5154
1 parent 5f3b21b commit 4d1ccfa

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

Classes/Domain/NodeCreation/NodeCreationService.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
2222
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
2323
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
24+
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
2425
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
2526
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
2627
use Neos\Flow\Annotations as Flow;
@@ -73,13 +74,26 @@ public function apply(RootTemplate $template, NodeCreationCommands $commands, No
7374
$template->getProperties()
7475
);
7576

77+
$propertyValuesToWrite = PropertyValuesToWrite::fromArray(
78+
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
79+
);
80+
81+
if (count($defaultPropertiesToUnset = iterator_to_array($propertyValuesToWrite->getPropertiesToUnset()))) {
82+
// FIXME workaround for https://github.com/neos/neos-development-collection/issues/5154
83+
$setDefaultPropertiesToNull = SetNodeProperties::create(
84+
$commands->first->workspaceName,
85+
$commands->first->nodeAggregateId,
86+
$commands->first->originDimensionSpacePoint,
87+
PropertyValuesToWrite::fromArray(
88+
array_fill_keys(array_map(fn (PropertyName $name) => $name->value, $defaultPropertiesToUnset), null)
89+
)
90+
);
91+
$commands = $commands->withAdditionalCommands($setDefaultPropertiesToNull);
92+
}
93+
7694
$initialProperties = $commands->first->initialPropertyValues;
7795

78-
$initialProperties = $initialProperties->merge(
79-
PropertyValuesToWrite::fromArray(
80-
$this->propertiesProcessor->processAndValidateProperties($node, $processingErrors)
81-
)
82-
);
96+
$initialProperties = $initialProperties->merge($propertyValuesToWrite);
8397

8498
$initialProperties = $this->ensureNodeHasUriPathSegment(
8599
$nodeType,

Tests/Functional/Features/Properties/Snapshots/Properties.nodes.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"properties": {
3-
"unsetValueWithDefault": null,
43
"someValueWithDefault": true,
54
"text": "abc",
65
"isEnchanted": false,
7-
"selectBox": "karma",
8-
"nullValue": null
6+
"selectBox": "karma"
97
},
108
"references": {
119
"reference": [

0 commit comments

Comments
 (0)