Skip to content

Commit c682516

Browse files
committed
FEATURE: Adjust disabled feature to work with NodeMutator architecture
- introduce $showDisabledNodesInSubgraph in tests to show disabled created nodes - introduce `NodeMutator::setDisabled` - updated all snapshots to include `"disabled": false,`
1 parent 17800c6 commit c682516

28 files changed

+150
-33
lines changed

Classes/Domain/NodeCreation/NodeCreationService.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ public function createMutatorsForRootTemplate(RootTemplate $template, NodeType $
5353
$this->referencesProcessor->processAndValidateReferences($node, $processingErrors)
5454
);
5555

56-
if ($template->getDisabled() === true) {
57-
$node->setHidden(true);
58-
}
59-
6056
return NodeMutatorCollection::from(
6157
NodeMutator::setProperties($validProperties),
58+
NodeMutator::setDisabled($template->getDisabled()),
6259
$this->createMutatorForUriPathSegment($template->getProperties()),
6360
)->merge(
6461
$this->createMutatorsForChildNodeTemplates(
@@ -71,7 +68,7 @@ public function createMutatorsForRootTemplate(RootTemplate $template, NodeType $
7168

7269
private function createMutatorsForChildNodeTemplates(Templates $templates, TransientNode $parentNode, ProcessingErrors $processingErrors): NodeMutatorCollection
7370
{
74-
$nodeMutators = NodeMutatorCollection::empty();
71+
$nodeMutators = NodeMutatorCollection::createEmpty();
7572

7673
// `hasAutoCreatedChildNode` actually has a bug; it looks up the NodeName parameter against the raw configuration instead of the transliterated NodeName
7774
// https://github.com/neos/neos-ui/issues/3527
@@ -157,6 +154,7 @@ private function createMutatorsForChildNodeTemplates(Templates $templates, Trans
157154
NodeMutatorCollection::from(
158155
NodeMutator::createAndSelectNode($template->getType(), $template->getName()),
159156
NodeMutator::setProperties($validProperties),
157+
NodeMutator::setDisabled($template->getDisabled()),
160158
$this->createMutatorForUriPathSegment($template->getProperties())
161159
)->merge($this->createMutatorsForChildNodeTemplates(
162160
$template->getChildNodes(),
@@ -168,10 +166,6 @@ private function createMutatorsForChildNodeTemplates(Templates $templates, Trans
168166

169167
}
170168

171-
if ($template->getDisabled() === true) {
172-
$node->setHidden(true);
173-
}
174-
175169
return $nodeMutators;
176170
}
177171

Classes/Domain/NodeCreation/NodeMutator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ public static function setProperties(array $properties): self
4848
});
4949
}
5050

51+
/**
52+
* Queues to disable the current node.
53+
*
54+
* Preserves the current node pointer.
55+
*/
56+
public static function setDisabled(bool $disabled): self
57+
{
58+
return new self(function (NodeInterface $nodePointer) use ($disabled) {
59+
$nodePointer->setHidden($disabled);
60+
return null;
61+
});
62+
}
63+
5164
/**
5265
* Queues to execute the collection {@see NodeMutatorCollection} on the current node.
5366
* Any selections made in the collection {@see self::selectChildNode()} won't change the pointer to $this current node.

Classes/Domain/NodeCreation/NodeMutatorCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function from(NodeMutator ...$items): self
2929
return new self(...$items);
3030
}
3131

32-
public static function empty(): self
32+
public static function createEmpty(): self
3333
{
3434
return new self();
3535
}

Classes/Domain/NodeCreation/PropertiesProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function assertValidPropertyName($propertyName): void
9595
if ($propertyName[0] === '_') {
9696
$lowerPropertyName = strtolower($propertyName);
9797
if ($lowerPropertyName === '_hidden') {
98-
throw new PropertyIgnoredException('Using "_hidden" as property declaration was removed. Please use "disabled" on the first level instead.');
98+
throw new PropertyIgnoredException('Using "_hidden" as property declaration was removed. Please use "disabled" on the first level instead.', 1719079679);
9999
}
100100
foreach ($legacyInternalProperties as $legacyInternalProperty) {
101101
if ($lowerPropertyName === strtolower($legacyInternalProperty)) {

Classes/Domain/Template/RootTemplate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class RootTemplate implements \JsonSerializable
1414
{
15-
private ?bool $disabled;
15+
private bool $disabled;
1616

1717
/**
1818
* @var array<string, mixed>
@@ -25,7 +25,7 @@ class RootTemplate implements \JsonSerializable
2525
* @internal
2626
* @param array<string, mixed> $properties
2727
*/
28-
public function __construct(?bool $disabled, array $properties, Templates $childNodes)
28+
public function __construct(bool $disabled, array $properties, Templates $childNodes)
2929
{
3030
$this->disabled = $disabled;
3131
$this->properties = $properties;
@@ -34,10 +34,10 @@ public function __construct(?bool $disabled, array $properties, Templates $child
3434

3535
public static function empty(): self
3636
{
37-
return new RootTemplate(null, [], Templates::empty());
37+
return new RootTemplate(false, [], Templates::empty());
3838
}
3939

40-
public function getDisabled(): ?bool
40+
public function getDisabled(): bool
4141
{
4242
return $this->disabled;
4343
}

Classes/Domain/Template/Template.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Template implements \JsonSerializable
1818

1919
private ?NodeName $name;
2020

21-
private ?bool $disabled;
21+
private bool $disabled;
2222

2323
/**
2424
* @var array<string, mixed>
@@ -31,7 +31,7 @@ class Template implements \JsonSerializable
3131
* @internal
3232
* @param array<string, mixed> $properties
3333
*/
34-
public function __construct(?NodeTypeName $type, ?NodeName $name, ?bool $disabled, array $properties, Templates $childNodes)
34+
public function __construct(?NodeTypeName $type, ?NodeName $name, bool $disabled, array $properties, Templates $childNodes)
3535
{
3636
$this->type = $type;
3737
$this->name = $name;
@@ -50,7 +50,7 @@ public function getName(): ?NodeName
5050
return $this->name;
5151
}
5252

53-
public function getDisabled(): ?bool
53+
public function getDisabled(): bool
5454
{
5555
return $this->disabled;
5656
}

Classes/Domain/TemplateConfiguration/TemplateConfigurationProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
139139
return new Template(
140140
$type !== null ? NodeTypeName::fromString($type) : null,
141141
$name !== null ? NodeName::fromString(Utility::renderValidNodeName($name)) : null,
142-
$templatePart->hasConfiguration('disabled') ? (bool)$templatePart->processConfiguration('disabled') : null,
142+
(bool)$templatePart->processConfiguration('disabled'),
143143
$processedProperties,
144144
$childNodeTemplates
145145
);

Tests/Functional/AbstractNodeTemplateTestCase.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ abstract class AbstractNodeTemplateTestCase extends FunctionalTestCase
2828
use WithConfigurationTrait;
2929
use FakeNodeTypeManagerTrait;
3030

31+
protected static bool $showDisabledNodesInSubgraph = false;
32+
3133
protected static $testablePersistenceEnabled = true;
3234

3335
private ContextFactoryInterface $contextFactory;
@@ -44,21 +46,21 @@ abstract class AbstractNodeTemplateTestCase extends FunctionalTestCase
4446

4547
private string $fixturesDir;
4648

47-
/** @deprecated please use {@see self::getObject()} instead */
49+
/** @internal please use {@see self::getObject()} instead */
4850
protected $objectManager;
4951

5052
public function setUp(): void
5153
{
5254
parent::setUp();
5355

54-
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
56+
$this->nodeTypeManager = $this->getObject(NodeTypeManager::class);
5557

5658
$this->loadFakeNodeTypes();
5759

5860
$this->setupContentRepository();
59-
$this->nodeTemplateDumper = $this->objectManager->get(NodeTemplateDumper::class);
61+
$this->nodeTemplateDumper = $this->getObject(NodeTemplateDumper::class);
6062

61-
$templateFactory = $this->objectManager->get(TemplateConfigurationProcessor::class);
63+
$templateFactory = $this->getObject(TemplateConfigurationProcessor::class);
6264

6365
$templateFactoryMock = $this->getMockBuilder(TemplateConfigurationProcessor::class)->disableOriginalConstructor()->getMock();
6466
$templateFactoryMock->expects(self::once())->method('processTemplateConfiguration')->willReturnCallback(function (...$args) use($templateFactory) {
@@ -76,7 +78,7 @@ public function tearDown(): void
7678
{
7779
parent::tearDown();
7880
$this->inject($this->contextFactory, 'contextInstances', []);
79-
$this->objectManager->get(FeedbackCollection::class)->reset();
81+
$this->getObject(FeedbackCollection::class)->reset();
8082
$this->objectManager->forgetInstance(ContentDimensionRepository::class);
8183
$this->objectManager->forgetInstance(TemplateConfigurationProcessor::class);
8284
$this->objectManager->forgetInstance(NodeTypeManager::class);
@@ -96,20 +98,20 @@ final protected function getObject(string $className): object
9698
private function setupContentRepository(): void
9799
{
98100
// Create an environment to create nodes.
99-
$this->objectManager->get(ContentDimensionRepository::class)->setDimensionsConfiguration([]);
101+
$this->getObject(ContentDimensionRepository::class)->setDimensionsConfiguration([]);
100102

101103
$liveWorkspace = new Workspace('live');
102-
$workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
104+
$workspaceRepository = $this->getObject(WorkspaceRepository::class);
103105
$workspaceRepository->add($liveWorkspace);
104106

105107
$testSite = new Site('test-site');
106108
$testSite->setSiteResourcesPackageKey('Test.Site');
107-
$siteRepository = $this->objectManager->get(SiteRepository::class);
109+
$siteRepository = $this->getObject(SiteRepository::class);
108110
$siteRepository->add($testSite);
109111

110112
$this->persistenceManager->persistAll();
111-
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
112-
$subgraph = $this->contextFactory->create(['workspaceName' => 'live']);
113+
$this->contextFactory = $this->getObject(ContextFactoryInterface::class);
114+
$subgraph = $this->contextFactory->create(['workspaceName' => 'live', 'invisibleContentShown' => static::$showDisabledNodesInSubgraph]);
113115

114116
$rootNode = $subgraph->getRootNode();
115117

@@ -153,7 +155,11 @@ protected function createNodeInto(NodeInterface $targetNode, string $nodeTypeNam
153155
assert($changeCollection instanceof ChangeCollection);
154156
$changeCollection->apply();
155157

156-
return $targetNode->getNode('new-node');
158+
$newNode = $targetNode->getNode('new-node');
159+
if (!$newNode) {
160+
throw new \RuntimeException('New node not found at expected location. Try settting $showDisabledNodesInSubgraph.', 1719079419);
161+
}
162+
return $newNode;
157163
}
158164

159165
protected function createFakeNode(string $nodeAggregateId): NodeInterface

Tests/Functional/Features/ChildNodes/Snapshots/AllowedChildNodes.template.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
2+
"disabled": false,
23
"properties": [],
34
"childNodes": [
45
{
56
"type": null,
67
"name": "content",
8+
"disabled": false,
79
"properties": [],
810
"childNodes": [
911
{
1012
"type": "Flowpack.NodeTemplates:Content.Text",
1113
"name": null,
14+
"disabled": false,
1215
"properties": {
1316
"text": "Text"
1417
},

Tests/Functional/Features/ChildNodes/Snapshots/ChildNodes.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
2+
"disabled": false,
23
"properties": [],
34
"childNodes": [
45
{
56
"type": null,
67
"name": "column0",
8+
"disabled": false,
79
"properties": [],
810
"childNodes": [
911
{
1012
"type": "Flowpack.NodeTemplates:Content.Text",
1113
"name": null,
14+
"disabled": false,
1215
"properties": {
1316
"text": "<p>foo<\/p>"
1417
},
@@ -19,11 +22,13 @@
1922
{
2023
"type": null,
2124
"name": "column1",
25+
"disabled": false,
2226
"properties": [],
2327
"childNodes": [
2428
{
2529
"type": "Flowpack.NodeTemplates:Content.Text",
2630
"name": null,
31+
"disabled": false,
2732
"properties": {
2833
"text": "<p>bar<\/p>"
2934
},

0 commit comments

Comments
 (0)