Skip to content

Commit b99832e

Browse files
committed
FEATURE: Add option to hide/disable nodes
This reverts commit 4fa4f45.
1 parent 4fa4f45 commit b99832e

18 files changed

Lines changed: 111 additions & 5 deletions

Classes/Domain/NodeCreation/NodeCreationService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function apply(RootTemplate $template, NodeInterface $node, CaughtExcepti
5353
$node->setProperty($key, $value);
5454
}
5555

56+
if ($template->getDisabled() === true) {
57+
$node->setHidden(true);
58+
}
59+
5660
$this->ensureNodeHasUriPathSegment($node, $template);
5761
$this->applyTemplateRecursively($template->getChildNodes(), $node, $caughtExceptions);
5862
}
@@ -110,6 +114,9 @@ private function applyTemplateRecursively(Templates $templates, NodeInterface $p
110114
$node->setProperty($key, $value);
111115
}
112116

117+
if ($template->getDisabled() === true) {
118+
$node->setHidden(true);
119+
}
113120
$this->ensureNodeHasUriPathSegment($node, $template);
114121
$this->applyTemplateRecursively($template->getChildNodes(), $node, $caughtExceptions);
115122
}

Classes/Domain/NodeCreation/PropertiesAndReferences.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ private function assertValidPropertyName($propertyName): void
120120
}
121121
if ($propertyName[0] === '_') {
122122
$lowerPropertyName = strtolower($propertyName);
123+
if ($lowerPropertyName === '_hidden') {
124+
throw new \InvalidArgumentException('Using "_hidden" as property declaration was removed. Please use "disabled" on the first level instead.');
125+
}
123126
foreach ($legacyInternalProperties as $legacyInternalProperty) {
124127
if ($lowerPropertyName === strtolower($legacyInternalProperty)) {
125128
throw new \InvalidArgumentException(sprintf('Internal legacy property "%s" not implement.', $propertyName));

Classes/Domain/Template/RootTemplate.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class RootTemplate implements \JsonSerializable
1616
{
17+
private ?bool $disabled;
18+
1719
/**
1820
* @var array<string, mixed>
1921
*/
@@ -25,12 +27,18 @@ class RootTemplate implements \JsonSerializable
2527
* @internal
2628
* @param array<string, mixed> $properties
2729
*/
28-
public function __construct(array $properties, Templates $childNodes)
30+
public function __construct(?bool $disabled, array $properties, Templates $childNodes)
2931
{
32+
$this->disabled = $disabled;
3033
$this->properties = $properties;
3134
$this->childNodes = $childNodes;
3235
}
3336

37+
public function getDisabled(): ?bool
38+
{
39+
return $this->disabled;
40+
}
41+
3442
/**
3543
* @return array<string, string>
3644
*/
@@ -47,6 +55,7 @@ public function getChildNodes(): Templates
4755
public function jsonSerialize()
4856
{
4957
return [
58+
'disabled' => $this->disabled,
5059
'properties' => $this->properties,
5160
'childNodes' => $this->childNodes
5261
];

Classes/Domain/Template/Template.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Template implements \JsonSerializable
1515

1616
private ?NodeName $name;
1717

18+
private ?bool $disabled;
19+
1820
/**
1921
* @var array<string, mixed>
2022
*/
@@ -26,10 +28,11 @@ class Template implements \JsonSerializable
2628
* @internal
2729
* @param array<string, mixed> $properties
2830
*/
29-
public function __construct(?NodeTypeName $type, ?NodeName $name, array $properties, Templates $childNodes)
31+
public function __construct(?NodeTypeName $type, ?NodeName $name, ?bool $disabled, array $properties, Templates $childNodes)
3032
{
3133
$this->type = $type;
3234
$this->name = $name;
35+
$this->disabled = $disabled;
3336
$this->properties = $properties;
3437
$this->childNodes = $childNodes;
3538
}
@@ -44,6 +47,11 @@ public function getName(): ?NodeName
4447
return $this->name;
4548
}
4649

50+
public function getDisabled(): ?bool
51+
{
52+
return $this->disabled;
53+
}
54+
4755
/**
4856
* @return array<string, string>
4957
*/
@@ -62,6 +70,7 @@ public function jsonSerialize()
6270
return [
6371
'type' => $this->type,
6472
'name' => $this->name,
73+
'disabled' => $this->disabled,
6574
'properties' => $this->properties,
6675
'childNodes' => $this->childNodes
6776
];

Classes/Domain/Template/Templates.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ public function toRootTemplate(): RootTemplate
4848
}
4949
foreach ($this->items as $first) {
5050
return new RootTemplate(
51+
$first->getDisabled(),
5152
$first->getProperties(),
5253
$first->getChildNodes()
5354
);
5455
}
55-
return new RootTemplate( [], Templates::empty());
56+
return new RootTemplate(null, [], Templates::empty());
5657
}
5758

5859
public function jsonSerialize()

Classes/Domain/TemplateConfiguration/TemplateConfigurationProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
111111
return new Template(
112112
$type ? NodeTypeName::fromString($type) : null,
113113
$name ? NodeName::fromString($name) : null,
114+
$templatePart->hasConfiguration('disabled') ? (bool)$templatePart->processConfiguration('disabled') : null,
114115
$processedProperties,
115116
$childNodeTemplates
116117
);

Classes/Domain/TemplateConfiguration/TemplatePart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ private function validateTemplateConfigurationKeys(): void
192192
{
193193
$isRootTemplate = $this->fullPathToConfiguration === [];
194194
foreach (array_keys($this->configuration) as $key) {
195-
if (!in_array($key, ['type', 'name', 'properties', 'childNodes', 'when', 'withItems', 'withContext'], true)) {
195+
if (!in_array($key, ['type', 'name', 'disabled', 'properties', 'childNodes', 'when', 'withItems', 'withContext'], true)) {
196196
throw new \InvalidArgumentException(sprintf('Template configuration has illegal key "%s"', $key));
197197
}
198198
if ($isRootTemplate) {
199-
if (!in_array($key, ['properties', 'childNodes', 'when', 'withContext'], true)) {
199+
if (!in_array($key, ['disabled', 'properties', 'childNodes', 'when', 'withContext'], true)) {
200200
throw new \InvalidArgumentException(sprintf('Root template configuration doesnt allow option "%s', $key));
201201
}
202202
}

Configuration/Testing/NodeTypes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
ui:
1515
label: "Text"
1616

17+
'Flowpack.NodeTemplates:Content.Hidden':
18+
superTypes:
19+
'Neos.Neos:Content': true
20+
options:
21+
template:
22+
disabled: true
23+
1724
'Flowpack.NodeTemplates:Content.DifferentPropertyTypes':
1825
superTypes:
1926
'Neos.Neos:Content': true

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ The following example creates three different text child nodes in the main conte
129129
We call conditions ``when`` and loops ``withItems`` (instead of ``if`` and ``forEach``),
130130
because it inspires a more declarative mood. The naming is inspired by Ansible.
131131
132+
## Disable nodes (previously called "hidden")
133+
134+
The following example disables a newly created node:
135+
136+
```yaml
137+
'Neos.NodeTypes:Page':
138+
options:
139+
template:
140+
disabled: true
141+
```
142+
132143
## EEL context variables
133144
134145
There are several variables available in the EEL context for example.

Tests/Functional/Fixtures/DifferentPropertyTypes.template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"disabled": null,
23
"properties": {
34
"text": "abc",
45
"isEnchanted": false,

0 commit comments

Comments
 (0)