Skip to content

Commit e9c5b29

Browse files
committed
Merge remote-tracking branch 'origin/2.0' into neos9
2 parents 6b9fc67 + b9891bc commit e9c5b29

13 files changed

Lines changed: 324 additions & 39 deletions

Classes/Application/Command/NodeTemplateCommandController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\TemplateConfigurationProcessor;
1111
use Neos\Flow\Annotations as Flow;
1212
use Neos\Flow\Cli\CommandController;
13+
use Neos\Neos\Domain\Service\ContentContext;
1314

1415
class NodeTemplateCommandController extends CommandController
1516
{
@@ -79,6 +80,7 @@ public function validateCommand(): void
7980
}
8081
$processingErrors = ProcessingErrors::create();
8182

83+
/** @var ContentContext $subgraph */
8284
$subgraph = $this->contextFactory->create();
8385

8486
$observableEmptyData = new class ([]) extends \ArrayObject
@@ -91,11 +93,15 @@ public function offsetExists($key): bool
9193
}
9294
};
9395

96+
$siteNode = $subgraph->getCurrentSiteNode();
97+
9498
$template = $this->templateConfigurationProcessor->processTemplateConfiguration(
9599
$templateConfiguration,
96100
[
97101
'data' => $observableEmptyData,
98-
'triggeringNode' => $subgraph->getRootNode(),
102+
'triggeringNode' => $siteNode, // @deprecated
103+
'site' => $siteNode,
104+
'parentNode' => $siteNode,
99105
],
100106
$processingErrors
101107
);
@@ -123,6 +129,9 @@ public function offsetExists($key): bool
123129

124130
$this->outputLine();
125131

132+
// sort so the result is deterministic in ci https://github.com/neos/flow-development-collection/issues/3300
133+
ksort($faultyNodeTypeTemplates);
134+
126135
$hasError = false;
127136
foreach ($faultyNodeTypeTemplates as $nodeTypeName => ['processingErrors' => $processingErrors, 'dataWasAccessed' => $dataWasAccessed]) {
128137
if ($dataWasAccessed) {

Classes/Domain/NodeCreation/PropertiesProcessor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Flowpack\NodeTemplates\Domain\ErrorHandling\ProcessingError;
66
use Flowpack\NodeTemplates\Domain\ErrorHandling\ProcessingErrors;
7+
use Neos\Error\Messages\Error;
78
use Neos\Flow\Property\Exception as PropertyMappingException;
89
use Neos\Flow\Property\PropertyMapper;
910
use Neos\Flow\Property\PropertyMappingConfiguration;
@@ -54,7 +55,11 @@ public function processAndValidateProperties(TransientNode $node, ProcessingErro
5455
$propertyValue = $this->propertyMapper->convert($propertyValue, $propertyType->getValue(), $propertyMappingConfiguration);
5556
$messages = $this->propertyMapper->getMessages();
5657
if ($messages->hasErrors()) {
57-
throw new PropertyIgnoredException($messages->getFirstError()->getMessage(), 1686779371122);
58+
// $messages->getFirstError() doesnt work see https://github.com/neos/flow-development-collection/issues/3370
59+
$flattenedErrors = $messages->getFlattenedErrors();
60+
/** @var Error $firstError */
61+
$firstError = current(current($flattenedErrors));
62+
throw new PropertyIgnoredException($firstError->getMessage(), 1686779371122);
5863
}
5964
}
6065

Classes/Domain/TemplateNodeCreationHandler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ public function handle(
6262
);
6363

6464
$evaluationContext = [
65-
// todo internal and legacy
6665
'data' => iterator_to_array($elements->serialized()),
67-
// todo evaluate which context variables
68-
'parentNode' => $subgraph->findNodeById($commands->first->parentNodeAggregateId),
69-
'subgraph' => $subgraph
66+
'site' => null, // todo
67+
'parentNode' => $subgraph->findNodeById($commands->first->parentNodeAggregateId)
7068
];
7169

7270
$processingErrors = ProcessingErrors::create();

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,28 @@ because it inspires a more declarative mood. The naming is inspired by Ansible.
159159

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

162-
| Variable name | Type | Description | Availability |
163-
|----------------|----------------------|------------------------------------------------------------|-----------------------|
164-
| data | array<string, mixed> | Data from the node creation dialog | Global |
165-
| triggeringNode | Node | The main node whose creation triggered template processing | Global |
166-
| item | mixed | The current item inside a withItems loop | Inside withItems loop |
167-
| key | string | The current key inside a withItems loop | Inside withItems loop |
162+
| Variable name | Type | Description | Availability |
163+
|------------------|------------------------|-------------------------------------------------------------------------------|-------------------------|
164+
| data | `array<string, mixed>` | Data from the node creation dialog | Global |
165+
| site | `Node` | The site node in which the new node be created in | Global |
166+
| parentNode | `Node` | The node where the new utmost node will be created inside | Global |
167+
| item | `mixed` | The current item value inside a loop | Inside `withItems` loop |
168+
| key | `string` | The current item key inside a loop | Inside `withItems` loop |
169+
170+
> **Notice**
171+
> `triggeringNode` was removed with version 3.0. Please use `site` or `parentNode` instead.
172+
173+
> **Warning**
174+
> The behaviour of `parentNode` changed from version 1.x to version 2.2
175+
> Previously it referenced the parent node of the current template part and its nesting.
176+
> With version 2.0 it was removed and 2.2 reintroduced the variable identifying the parent node of the first/utmost node that will be created.
168177

169178
### Additional context
170179

171180
You can add more context variables to a template via the ``withContext`` setting. ``withContext``
172181
takes an arbitrary array of items whose values might also contain EEL expressions:
173182

174-
```
183+
```yaml
175184
template:
176185
withContext:
177186
someText: '<p>foo</p>'

Tests/Functional/AbstractNodeTemplateTestCase.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\TemplateConfigurationProcessor;
1010
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
1111
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
12-
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
1312
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
1413
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Command\CreateRootNodeAggregateWithNode;
1514
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateRootWorkspace;
@@ -19,6 +18,7 @@
1918
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindSubtreeFilter;
2019
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
2120
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
21+
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
2222
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
2323
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
2424
use Neos\ContentRepository\Core\SharedModel\User\UserId;
@@ -27,24 +27,21 @@
2727
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
2828
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle;
2929
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeUserIdProvider;
30-
use Neos\ContentRepositoryRegistry\Factory\ProjectionCatchUpTrigger\CatchUpTriggerWithSynchronousOption;
31-
use Neos\Flow\Configuration\ConfigurationManager;
3230
use Neos\Flow\Core\Bootstrap;
3331
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
3432
use Neos\Neos\FrontendRouting\NodeAddressFactory;
3533
use Neos\Neos\Ui\Domain\Model\ChangeCollection;
3634
use Neos\Neos\Ui\Domain\Model\FeedbackCollection;
3735
use Neos\Neos\Ui\TypeConverter\ChangeCollectionConverter;
38-
use Neos\Utility\Arrays;
3936
use PHPUnit\Framework\TestCase;
40-
use Symfony\Component\Yaml\Yaml;
4137

4238
abstract class AbstractNodeTemplateTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
4339
{
4440
use SnapshotTrait;
4541
use FeedbackCollectionMessagesTrait;
4642
use JsonSerializeNodeTreeTrait;
4743
use WithConfigurationTrait;
44+
use FakeNodeTypeManagerTrait;
4845

4946
use ContentRepositoryTestTrait;
5047

@@ -85,27 +82,6 @@ public function setUp(): void
8582
$this->fixturesDir = dirname($ref->getFileName()) . '/Snapshots';
8683
}
8784

88-
private function loadFakeNodeTypes(): void
89-
{
90-
$configuration = $this->objectManager->get(ConfigurationManager::class)->getConfiguration('NodeTypes');
91-
92-
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/Features'));
93-
94-
/** @var \SplFileInfo $fileInfo */
95-
foreach ($fileIterator as $fileInfo) {
96-
if (!$fileInfo->isFile() || $fileInfo->getExtension() !== 'yaml' || strpos($fileInfo->getBasename(), 'NodeTypes.') !== 0) {
97-
continue;
98-
}
99-
100-
$configuration = Arrays::arrayMergeRecursiveOverrule(
101-
$configuration,
102-
Yaml::parseFile($fileInfo->getRealPath()) ?? []
103-
);
104-
}
105-
106-
$this->nodeTypeManager->overrideNodeTypes($configuration);
107-
}
108-
10985
public function tearDown(): void
11086
{
11187
$this->objectManager->get(FeedbackCollection::class)->reset();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\NodeTemplates\Tests\Functional;
6+
7+
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
8+
use Neos\Flow\Configuration\ConfigurationManager;
9+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
10+
use Neos\Utility\Arrays;
11+
use Symfony\Component\Yaml\Yaml;
12+
13+
/**
14+
* @property ObjectManagerInterface $objectManager
15+
* @property NodeTypeManager $nodeTypeManager
16+
*/
17+
trait FakeNodeTypeManagerTrait
18+
{
19+
private function loadFakeNodeTypes(): void
20+
{
21+
$configuration = $this->objectManager->get(ConfigurationManager::class)->getConfiguration('NodeTypes');
22+
23+
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/Features'));
24+
25+
/** @var \SplFileInfo $fileInfo */
26+
foreach ($fileIterator as $fileInfo) {
27+
if (!$fileInfo->isFile() || $fileInfo->getExtension() !== 'yaml' || strpos($fileInfo->getBasename(), 'NodeTypes.') !== 0) {
28+
continue;
29+
}
30+
31+
$configuration = Arrays::arrayMergeRecursiveOverrule(
32+
$configuration,
33+
Yaml::parseFile($fileInfo->getRealPath()) ?? []
34+
);
35+
}
36+
37+
$this->nodeTypeManager->overrideNodeTypes($configuration);
38+
}
39+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
10 of 15 NodeType template validated. 5 could not be build standalone.
2+
3+
Flowpack.NodeTemplates:Content.DisallowedChildNodes
4+
NodeConstraintException(Node type "Flowpack.NodeTemplates:Content.Text" is not allowed below tethered child nodes "content" of nodes of type "Flowpack.NodeTemplates:Content.DisallowedChildNodes", 1687541480146)
5+
6+
NodeConstraintException(Node type "Flowpack.NodeTemplates:Document.Page" is not allowed for child nodes of type Flowpack.NodeTemplates:Content.DisallowedChildNodes, 1686417627173)
7+
8+
Flowpack.NodeTemplates:Content.OnlyExceptions
9+
Expression "${'left open" in "childNodes.abort.when" | EelException(The EEL expression "${'left open" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)
10+
11+
Flowpack.NodeTemplates:Content.ResolvableProperties <b>(depends on "data" context)</b>
12+
Property "asset" in NodeType "Flowpack.NodeTemplates:Content.ResolvableProperties" | PropertyIgnoredException(Object of type Neos\Media\Domain\Model\Asset with identity "c228200e-7472-4290-9936-4454a5b5692a" not found., 1686779371122)
13+
14+
Property "images" in NodeType "Flowpack.NodeTemplates:Content.ResolvableProperties" | PropertyIgnoredException(Object of type Neos\Media\Domain\Model\ImageInterface with identity "c8ae9f9f-dd11-4373-bf42-4bf31ec5bd19" not found., 1686779371122)
15+
16+
Reference "reference" in NodeType "Flowpack.NodeTemplates:Content.ResolvableProperties" | InvalidReferenceException(Node with identifier "some-node-id" does not exist., 1687632330292)
17+
18+
Reference "references" in NodeType "Flowpack.NodeTemplates:Content.ResolvableProperties" | InvalidReferenceException(Invalid reference value. Value `["some-node-id","other-node-id",null]` is not a valid list of nodes or node identifiers., 1685958176560)
19+
20+
Flowpack.NodeTemplates:Content.SomeExceptions
21+
Expression "${cannotCallThis()}" in "properties.foo" | NotAllowedException(Method "cannotCallThis" is not callable in untrusted context, 1369043080)
22+
23+
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)
24+
25+
Configuration "properties.nonEelArrayNotAllowed" | RuntimeException(Template configuration properties can only hold int|float|string|bool|null. Property "nonEelArrayNotAllowed" has type "array", 1685725310730)
26+
27+
Expression "${parse äüäö error}" in "childNodes.whenAbort.when" | ParserException(Expression "parse äüäö error" could not be parsed. Error starting at character 5: " äüäö error"., 1327682383)
28+
29+
Expression "${}" in "childNodes.withContextAbort.withContext.foo" | ParserException(Expression "" could not be parsed., 1344513194)
30+
31+
Expression "${Array.map()}" in "childNodes.withItemsAbort.withItems" | ArgumentCountError(Too few arguments to function Neos\Eel\Helper\ArrayHelper::map(), 0 passed and exactly 2 expected, 0)
32+
33+
Expression "${" in "childNodes.propertiesPartiallyWorking.properties.propertyIsExcludedFromTemplate" | EelException(The EEL expression "${" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)
34+
35+
Expression "${" in "childNodes.typeAbort.type" | EelException(The EEL expression "${" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)
36+
37+
Expression "${" in "childNodes.nameAbort.name" | EelException(The EEL expression "${" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)
38+
39+
Expression "${item == 1 ? cannotCallThis() : null}" in "childNodes.withItemsPartiallyWorking.name" | NotAllowedException(Method "cannotCallThis" is not callable in untrusted context, 1369043080)
40+
41+
Configuration "childNodes.withItemsAbortBecauseNotIterable.withItems" | RuntimeException(Type NULL is not iterable., 1685802354186)
42+
43+
Configuration "childNodes.invalidOption.crazy" | InvalidArgumentException(Template configuration has illegal key "crazy", 1686150349274)
44+
45+
Property "_hidden" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | PropertyIgnoredException(Because internal legacy property "_hidden" not implement., 1686149513158)
46+
47+
Property "_hiddenAfterDateTime" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | PropertyIgnoredException(Because internal legacy property "_hiddenAfterDateTime" not implement., 1686149513158)
48+
49+
Property "boolValue" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | PropertyIgnoredException(Because value `123` is not assignable to property type "boolean"., 1685958105644)
50+
51+
Property "stringValue" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | PropertyIgnoredException(Because value `false` is not assignable to property type "string"., 1685958105644)
52+
53+
Property "nonDeclaredProperty" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | PropertyIgnoredException(Because property is not declared in NodeType. Got value `"hi"`., 1685869035209)
54+
55+
Reference "reference" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | InvalidReferenceException(Node with identifier "non-existing-node-id" does not exist., 1687632330292)
56+
57+
Reference "references" in NodeType "Flowpack.NodeTemplates:Content.SomeExceptions" | InvalidReferenceException(Node with identifier "non-existing-node-id" does not exist., 1687632330292)
58+
59+
RuntimeException(Template requires type to be a non abstract NodeType. Got: "Neos.Neos:Node"., 1686417628976)
60+
61+
NodeConstraintException(Node type "Flowpack.NodeTemplates:Document.Page" is not allowed for child nodes of type Flowpack.NodeTemplates:Content.SomeExceptions, 1686417627173)
62+
63+
RuntimeException(Template requires type to be set for non auto created child nodes., 1685999829307)
64+
65+
RuntimeException(Template requires type to be a valid NodeType. Got: "Flowpack.NodeTemplates:InvalidNodeType"., 1685999795564)
66+
67+
RuntimeException(Template cant mutate type of auto created child nodes. Got: "Flowpack.NodeTemplates:Content.SomeExceptions", 1685999829307)
68+
69+
Flowpack.NodeTemplates:Content.UnresolvableProperties
70+
Property "someString" in NodeType "Flowpack.NodeTemplates:Content.UnresolvableProperties" | PropertyIgnoredException(Because value `["foo"]` is not assignable to property type "string"., 1685958105644)
71+
72+
Property "asset" in NodeType "Flowpack.NodeTemplates:Content.UnresolvableProperties" | PropertyIgnoredException(Object of type "Neos\Media\Domain\Model\Asset" with identity "non-existing" not found., 1686779371122)
73+
74+
Property "images" in NodeType "Flowpack.NodeTemplates:Content.UnresolvableProperties" | FlowException(Could not convert target type "array<Neos\Media\Domain\Model\ImageInterface>", at property path "0": No converter found which can be used to convert from "string" to "Neos\Media\Domain\Model\ImageInterface"., 1297759968) | TypeConverterException(No converter found which can be used to convert from "string" to "Neos\Media\Domain\Model\ImageInterface"., 0)
75+
76+
Reference "reference" in NodeType "Flowpack.NodeTemplates:Content.UnresolvableProperties" | InvalidReferenceException(Invalid reference value. Value `true` is not a valid node or node identifier., 1687632177555)
77+
78+
Reference "references" in NodeType "Flowpack.NodeTemplates:Content.UnresolvableProperties" | InvalidReferenceException(Node with identifier "some-non-existing-node-id" does not exist., 1687632330292)

0 commit comments

Comments
 (0)