Skip to content

Commit 17800c6

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

File tree

8 files changed

+47
-5
lines changed

8 files changed

+47
-5
lines changed

Classes/Domain/NodeCreation/NodeCreationService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ 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+
5660
return NodeMutatorCollection::from(
5761
NodeMutator::setProperties($validProperties),
5862
$this->createMutatorForUriPathSegment($template->getProperties()),
@@ -164,6 +168,10 @@ private function createMutatorsForChildNodeTemplates(Templates $templates, Trans
164168

165169
}
166170

171+
if ($template->getDisabled() === true) {
172+
$node->setHidden(true);
173+
}
174+
167175
return $nodeMutators;
168176
}
169177

Classes/Domain/NodeCreation/PropertiesProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ private function assertValidPropertyName($propertyName): void
9494
}
9595
if ($propertyName[0] === '_') {
9696
$lowerPropertyName = strtolower($propertyName);
97+
if ($lowerPropertyName === '_hidden') {
98+
throw new PropertyIgnoredException('Using "_hidden" as property declaration was removed. Please use "disabled" on the first level instead.');
99+
}
97100
foreach ($legacyInternalProperties as $legacyInternalProperty) {
98101
if ($lowerPropertyName === strtolower($legacyInternalProperty)) {
99102
throw new PropertyIgnoredException(sprintf('Because internal legacy property "%s" not implement.', $propertyName), 1686149513158);

Classes/Domain/Template/RootTemplate.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class RootTemplate implements \JsonSerializable
1414
{
15+
private ?bool $disabled;
16+
1517
/**
1618
* @var array<string, mixed>
1719
*/
@@ -23,15 +25,21 @@ class RootTemplate implements \JsonSerializable
2325
* @internal
2426
* @param array<string, mixed> $properties
2527
*/
26-
public function __construct(array $properties, Templates $childNodes)
28+
public function __construct(?bool $disabled, array $properties, Templates $childNodes)
2729
{
30+
$this->disabled = $disabled;
2831
$this->properties = $properties;
2932
$this->childNodes = $childNodes;
3033
}
3134

3235
public static function empty(): self
3336
{
34-
return new RootTemplate([], Templates::empty());
37+
return new RootTemplate(null, [], Templates::empty());
38+
}
39+
40+
public function getDisabled(): ?bool
41+
{
42+
return $this->disabled;
3543
}
3644

3745
/**
@@ -50,6 +58,7 @@ public function getChildNodes(): Templates
5058
public function jsonSerialize(): array
5159
{
5260
return [
61+
'disabled' => $this->disabled,
5362
'properties' => $this->properties,
5463
'childNodes' => $this->childNodes
5564
];

Classes/Domain/Template/Template.php

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

1919
private ?NodeName $name;
2020

21+
private ?bool $disabled;
22+
2123
/**
2224
* @var array<string, mixed>
2325
*/
@@ -29,10 +31,11 @@ class Template implements \JsonSerializable
2931
* @internal
3032
* @param array<string, mixed> $properties
3133
*/
32-
public function __construct(?NodeTypeName $type, ?NodeName $name, array $properties, Templates $childNodes)
34+
public function __construct(?NodeTypeName $type, ?NodeName $name, ?bool $disabled, array $properties, Templates $childNodes)
3335
{
3436
$this->type = $type;
3537
$this->name = $name;
38+
$this->disabled = $disabled;
3639
$this->properties = $properties;
3740
$this->childNodes = $childNodes;
3841
}
@@ -47,6 +50,11 @@ public function getName(): ?NodeName
4750
return $this->name;
4851
}
4952

53+
public function getDisabled(): ?bool
54+
{
55+
return $this->disabled;
56+
}
57+
5058
/**
5159
* @return array<string, string>
5260
*/
@@ -65,6 +73,7 @@ public function jsonSerialize(): array
6573
return [
6674
'type' => $this->type,
6775
'name' => $this->name,
76+
'disabled' => $this->disabled,
6877
'properties' => $this->properties,
6978
'childNodes' => $this->childNodes
7079
];

Classes/Domain/Template/Templates.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function toRootTemplate(): RootTemplate
5050
}
5151
foreach ($this->items as $first) {
5252
return new RootTemplate(
53+
$first->getDisabled(),
5354
$first->getProperties(),
5455
$first->getChildNodes()
5556
);

Classes/Domain/TemplateConfiguration/TemplateConfigurationProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +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,
142143
$processedProperties,
143144
$childNodeTemplates
144145
);

Classes/Domain/TemplateConfiguration/TemplatePart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ private function validateTemplateConfigurationKeys(): void
210210
{
211211
$isRootTemplate = $this->fullPathToConfiguration === [];
212212
foreach (array_keys($this->configuration) as $key) {
213-
if (!in_array($key, ['type', 'name', 'properties', 'childNodes', 'when', 'withItems', 'withContext'], true)) {
213+
if (!in_array($key, ['type', 'name', 'disabled', 'properties', 'childNodes', 'when', 'withItems', 'withContext'], true)) {
214214
$this->addProcessingErrorForPath(
215215
new \InvalidArgumentException(sprintf('Template configuration has illegal key "%s"', $key), 1686150349274),
216216
$key
217217
);
218218
throw new StopBuildingTemplatePartException();
219219
}
220220
if ($isRootTemplate) {
221-
if (!in_array($key, ['properties', 'childNodes', 'when', 'withContext'], true)) {
221+
if (!in_array($key, ['disabled', 'properties', 'childNodes', 'when', 'withContext'], true)) {
222222
$this->addProcessingErrorForPath(
223223
new \InvalidArgumentException(sprintf('Root template configuration doesnt allow option "%s', $key), 1686150340657),
224224
$key

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ The following example creates three different text child nodes in the main conte
155155
We call conditions ``when`` and loops ``withItems`` (instead of ``if`` and ``forEach``),
156156
because it inspires a more declarative mood. The naming is inspired by Ansible.
157157

158+
## Disable nodes (in version 1.0 "_hidden")
159+
160+
The following example disables a newly created node:
161+
162+
```yaml
163+
'Neos.NodeTypes:Page':
164+
options:
165+
template:
166+
disabled: true
167+
```
168+
158169
## EEL context variables
159170

160171
There are several variables available in the EEL context for example.

0 commit comments

Comments
 (0)