Skip to content

Commit 0f95072

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/reintroduceHiddenOrDisabledNodes
2 parents b99832e + a3684ba commit 0f95072

File tree

10 files changed

+72
-24
lines changed

10 files changed

+72
-24
lines changed

Classes/Domain/ExceptionHandling/ExceptionHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ class ExceptionHandler
3131
protected $throwableStorage;
3232

3333
/**
34+
* @var ExceptionHandlingConfiguration
3435
* @Flow\Inject
3536
*/
36-
protected ExceptionHandlingConfiguration $configuration;
37+
protected $configuration;
3738

3839
public function handleAfterTemplateConfigurationProcessing(CaughtExceptions $caughtExceptions, NodeInterface $node): void
3940
{

Classes/Domain/NodeCreation/PropertiesAndReferences.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ public static function createFromArrayAndTypeDeclarations(array $propertiesAndRe
5353
public function requireValidProperties(NodeType $nodeType, CaughtExceptions $caughtExceptions): array
5454
{
5555
$validProperties = [];
56-
$defaultValues = $nodeType->getDefaultValuesForProperties();
5756
foreach ($this->properties as $propertyName => $propertyValue) {
58-
$this->assertValidPropertyName($propertyName);
5957
try {
58+
$this->assertValidPropertyName($propertyName);
6059
if (!isset($nodeType->getProperties()[$propertyName])) {
6160
throw new PropertyIgnoredException(
6261
sprintf(
@@ -109,14 +108,14 @@ public function requireValidReferences(NodeType $nodeType, Context $subgraph, Ca
109108

110109
/**
111110
* In the old CR, it was common practice to set internal or meta properties via this syntax: `_hidden` but we don't allow this anymore.
112-
* @throws \InvalidArgumentException
111+
* @throws PropertyIgnoredException
113112
*/
114113
private function assertValidPropertyName($propertyName): void
115114
{
116115
$legacyInternalProperties = ['_accessRoles', '_contentObject', '_hidden', '_hiddenAfterDateTime', '_hiddenBeforeDateTime', '_hiddenInIndex',
117116
'_index', '_name', '_nodeType', '_removed', '_workspace'];
118117
if (!is_string($propertyName) || $propertyName === '') {
119-
throw new \InvalidArgumentException(sprintf('Property name must be a non empty string. Got "%s".', $propertyName));
118+
throw new PropertyIgnoredException(sprintf('Because property name must be a non empty string. Got "%s".', $propertyName), 1686149518395);
120119
}
121120
if ($propertyName[0] === '_') {
122121
$lowerPropertyName = strtolower($propertyName);
@@ -125,7 +124,7 @@ private function assertValidPropertyName($propertyName): void
125124
}
126125
foreach ($legacyInternalProperties as $legacyInternalProperty) {
127126
if ($lowerPropertyName === strtolower($legacyInternalProperty)) {
128-
throw new \InvalidArgumentException(sprintf('Internal legacy property "%s" not implement.', $propertyName));
127+
throw new PropertyIgnoredException(sprintf('Because internal legacy property "%s" not implement.', $propertyName), 1686149513158);
129128
}
130129
}
131130
}

Classes/Domain/Template/RootTemplate.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
namespace Flowpack\NodeTemplates\Domain\Template;
55

6-
use Flowpack\NodeTemplates\Domain\Template\Template;
7-
use Flowpack\NodeTemplates\Domain\Template\Templates;
86
use Neos\Flow\Annotations as Flow;
97

108
/**
@@ -34,6 +32,11 @@ public function __construct(?bool $disabled, array $properties, Templates $child
3432
$this->childNodes = $childNodes;
3533
}
3634

35+
public static function empty(): self
36+
{
37+
return new RootTemplate(null, [], Templates::empty());
38+
}
39+
3740
public function getDisabled(): ?bool
3841
{
3942
return $this->disabled;

Classes/Domain/Template/Template.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
namespace Flowpack\NodeTemplates\Domain\Template;
55

6-
use Flowpack\NodeTemplates\Domain\Template\Templates;
7-
use Neos\ContentRepository\Domain\NodeType\NodeTypeName;
86
use Neos\ContentRepository\Domain\NodeAggregate\NodeName;
7+
use Neos\ContentRepository\Domain\NodeType\NodeTypeName;
98
use Neos\Flow\Annotations as Flow;
109

1110
/** @Flow\Proxy(false) */

Classes/Domain/Template/Templates.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Flowpack\NodeTemplates\Domain\Template;
44

5-
use Flowpack\NodeTemplates\Domain\Template\RootTemplate;
6-
use Flowpack\NodeTemplates\Domain\Template\Template;
75
use Neos\Flow\Annotations as Flow;
86

97
/** @Flow\Proxy(false) */
@@ -53,7 +51,7 @@ public function toRootTemplate(): RootTemplate
5351
$first->getChildNodes()
5452
);
5553
}
56-
return new RootTemplate(null, [], Templates::empty());
54+
return RootTemplate::empty();
5755
}
5856

5957
public function jsonSerialize()

Classes/Domain/TemplateConfiguration/TemplateConfigurationProcessor.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Flowpack\NodeTemplates\Domain\Template\RootTemplate;
88
use Flowpack\NodeTemplates\Domain\Template\Template;
99
use Flowpack\NodeTemplates\Domain\Template\Templates;
10-
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\EelEvaluationService;
1110
use Neos\ContentRepository\Domain\NodeAggregate\NodeName;
1211
use Neos\ContentRepository\Domain\NodeType\NodeTypeName;
1312
use Neos\Flow\Annotations as Flow;
@@ -31,12 +30,16 @@ class TemplateConfigurationProcessor
3130
*/
3231
public function processTemplateConfiguration(array $configuration, array $evaluationContext, CaughtExceptions $caughtEvaluationExceptions): RootTemplate
3332
{
34-
$templatePart = TemplatePart::createRoot(
35-
$configuration,
36-
$evaluationContext,
37-
fn ($value, $evaluationContext) => $this->preprocessConfigurationValue($value, $evaluationContext),
38-
$caughtEvaluationExceptions
39-
);
33+
try {
34+
$templatePart = TemplatePart::createRoot(
35+
$configuration,
36+
$evaluationContext,
37+
fn ($value, $evaluationContext) => $this->preprocessConfigurationValue($value, $evaluationContext),
38+
$caughtEvaluationExceptions
39+
);
40+
} catch (StopBuildingTemplatePartException $e) {
41+
return RootTemplate::empty();
42+
}
4043
return $this->createTemplatesFromTemplatePart($templatePart)->toRootTemplate();
4144
}
4245

@@ -91,7 +94,10 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
9194
$processedProperties = [];
9295
foreach ($templatePart->getRawConfiguration('properties') ?? [] as $propertyName => $value) {
9396
if (!is_scalar($value) && !is_null($value)) {
94-
throw new \InvalidArgumentException(sprintf('Template configuration properties can only hold int|float|string|bool|null. Property "%s" has type "%s"', $propertyName, gettype($value)), 1685725310730);
97+
$templatePart->getCaughtExceptions()->add(CaughtException::fromException(
98+
new \RuntimeException(sprintf('Template configuration properties can only hold int|float|string|bool|null. Property "%s" has type "%s"', $propertyName, gettype($value)), 1685725310730)
99+
));
100+
continue;
95101
}
96102
try {
97103
$processedProperties[$propertyName] = $templatePart->processConfiguration(['properties', $propertyName]);
@@ -102,7 +108,11 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
102108
// process the childNodes
103109
$childNodeTemplates = Templates::empty();
104110
foreach ($templatePart->getRawConfiguration('childNodes') ?? [] as $childNodeConfigurationPath => $_) {
105-
$childNodeTemplatePart = $templatePart->withConfigurationByConfigurationPath(['childNodes', $childNodeConfigurationPath]);
111+
try {
112+
$childNodeTemplatePart = $templatePart->withConfigurationByConfigurationPath(['childNodes', $childNodeConfigurationPath]);
113+
} catch (StopBuildingTemplatePartException $e) {
114+
continue;
115+
}
106116
$childNodeTemplates = $childNodeTemplates->merge($this->createTemplatesFromTemplatePart($childNodeTemplatePart));
107117
}
108118

Classes/Domain/TemplateConfiguration/TemplatePart.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class TemplatePart
4343
* @psalm-param array<string, mixed> $configuration
4444
* @psalm-param array<string, mixed> $evaluationContext
4545
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
46+
* @throws StopBuildingTemplatePartException
4647
*/
4748
private function __construct(
4849
array $configuration,
@@ -63,6 +64,7 @@ private function __construct(
6364
* @psalm-param array<string, mixed> $configuration
6465
* @psalm-param array<string, mixed> $evaluationContext
6566
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
67+
* @throws StopBuildingTemplatePartException
6668
*/
6769
public static function createRoot(
6870
array $configuration,
@@ -91,6 +93,7 @@ public function getFullPathToConfiguration(): array
9193

9294
/**
9395
* @psalm-param string|list<string> $configurationPath
96+
* @throws StopBuildingTemplatePartException
9497
*/
9598
public function withConfigurationByConfigurationPath($configurationPath): self
9699
{
@@ -188,16 +191,25 @@ public function hasConfiguration($configurationPath): bool
188191
return true;
189192
}
190193

194+
/**
195+
* @throws StopBuildingTemplatePartException
196+
*/
191197
private function validateTemplateConfigurationKeys(): void
192198
{
193199
$isRootTemplate = $this->fullPathToConfiguration === [];
194200
foreach (array_keys($this->configuration) as $key) {
195201
if (!in_array($key, ['type', 'name', 'disabled', 'properties', 'childNodes', 'when', 'withItems', 'withContext'], true)) {
196-
throw new \InvalidArgumentException(sprintf('Template configuration has illegal key "%s"', $key));
202+
$this->caughtExceptions->add(
203+
CaughtException::fromException(new \InvalidArgumentException(sprintf('Template configuration has illegal key "%s"', $key), 1686150349274))
204+
);
205+
throw new StopBuildingTemplatePartException();
197206
}
198207
if ($isRootTemplate) {
199208
if (!in_array($key, ['disabled', 'properties', 'childNodes', 'when', 'withContext'], true)) {
200-
throw new \InvalidArgumentException(sprintf('Root template configuration doesnt allow option "%s', $key));
209+
$this->caughtExceptions->add(
210+
CaughtException::fromException(new \InvalidArgumentException(sprintf('Root template configuration doesnt allow option "%s', $key), 1686150340657))
211+
);
212+
throw new StopBuildingTemplatePartException();
201213
}
202214
}
203215
}

Configuration/Testing/NodeTypes.Malformed.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@
3333
template:
3434
properties:
3535
foo: "${cannotCallThis()}"
36+
# legacy properties fail
37+
_hidden: true
38+
_hiddenAfterDateTime: 123
3639
boolValue: 123
3740
stringValue: false
3841
reference: "non-existing-node-id"
3942
references: "${['non-existing-node-id']}"
4043
working: "working"
4144
nonDeclaredProperty: "hi"
4245
bar: "${'left open"
46+
# only simple scalar types
47+
nonEelArrayNotAllowed:
48+
not: allowed
4349
childNodes:
4450
whenAbort:
4551
type: 'Flowpack.NodeTemplates:Content.Text'
@@ -85,3 +91,5 @@
8591
typeCantMutate:
8692
name: "type-cant-mutate"
8793
type: "Flowpack.NodeTemplates:Content.WithEvaluationExceptions"
94+
invalidOption:
95+
crazy: me

Tests/Functional/Fixtures/WithEvaluationExceptions.messages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"message": "Expression \"${'left open\" in \"properties.bar\" | EelException(The EEL expression \"${'left open\" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)",
1212
"severity": "ERROR"
1313
},
14+
{
15+
"message": "RuntimeException(Template configuration properties can only hold int|float|string|bool|null. Property \"nonEelArrayNotAllowed\" has type \"array\", 1685725310730)",
16+
"severity": "ERROR"
17+
},
1418
{
1519
"message": "Expression \"${parse \u00e4\u00fc\u00e4\u00f6 error}\" in \"childNodes.whenAbort.when\" | ParserException(Expression \"parse \u00e4\u00fc\u00e4\u00f6 error\" could not be parsed. Error starting at character 5: \" \u00e4\u00fc\u00e4\u00f6 error\"., 1327682383)",
1620
"severity": "ERROR"
@@ -43,6 +47,18 @@
4347
"message": "Configuration \"null\" in \"childNodes.withItemsAbortBecauseNotIterable.withItems\" | RuntimeException(Type NULL is not iterable., 1685802354186)",
4448
"severity": "ERROR"
4549
},
50+
{
51+
"message": "InvalidArgumentException(Template configuration has illegal key \"crazy\", 1686150349274)",
52+
"severity": "ERROR"
53+
},
54+
{
55+
"message": "Property \"_hidden\" in NodeType \"Flowpack.NodeTemplates:Content.WithEvaluationExceptions\" | PropertyIgnoredException(Because internal legacy property \"_hidden\" not implement., 1686149513158)",
56+
"severity": "ERROR"
57+
},
58+
{
59+
"message": "Property \"_hiddenAfterDateTime\" in NodeType \"Flowpack.NodeTemplates:Content.WithEvaluationExceptions\" | PropertyIgnoredException(Because internal legacy property \"_hiddenAfterDateTime\" not implement., 1686149513158)",
60+
"severity": "ERROR"
61+
},
4662
{
4763
"message": "Property \"boolValue\" in NodeType \"Flowpack.NodeTemplates:Content.WithEvaluationExceptions\" | PropertyIgnoredException(Because value `123` is not assignable to property type \"boolean\"., 1685958105644)",
4864
"severity": "ERROR"

Tests/Functional/Fixtures/WithEvaluationExceptions.template.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"disabled": null,
33
"properties": {
4+
"_hidden": true,
5+
"_hiddenAfterDateTime": 123,
46
"boolValue": 123,
57
"stringValue": false,
68
"reference": "non-existing-node-id",

0 commit comments

Comments
 (0)