Skip to content

Commit 7900bd7

Browse files
authored
Merge pull request #82 from Flowpack/task/costmeticAdjustmentsForVersion2
TASK: Costmetic adjustments for version2
2 parents b9891bc + 853ffc2 commit 7900bd7

File tree

14 files changed

+111
-120
lines changed

14 files changed

+111
-120
lines changed

Classes/Application/Command/NodeTemplateCommandController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class NodeTemplateCommandController extends CommandController
5151
* Dump the node tree structure into a NodeTemplate YAML structure.
5252
* References to Nodes and non-primitive property values are commented out in the YAML.
5353
*
54-
* @param string $startingNodeId specified root node of the node tree
55-
* @param string $workspaceName
54+
* @param string $startingNodeId specified root node of the node tree.
55+
* @param string $workspaceName custom workspace to dump from. Defaults to 'live'.
5656
* @return void
5757
*/
5858
public function createFromNodeSubtreeCommand(string $startingNodeId, string $workspaceName = 'live'): void

Classes/Domain/NodeTemplateDumper/Comment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
class Comment
1616
{
1717
/**
18-
* @psalm-var \Closure(string $indentation, string $propertyName): string $renderFunction
18+
* @var \Closure(string $indentation, string $propertyName): string $renderFunction
1919
*/
2020
private \Closure $renderFunction;
2121

2222
/**
23-
* @psalm-param \Closure(string $indentation, string $propertyName): string $renderFunction
23+
* @param \Closure(string $indentation, string $propertyName): string $renderFunction
2424
*/
2525
private function __construct(\Closure $renderFunction)
2626
{
2727
$this->renderFunction = $renderFunction;
2828
}
2929

3030
/**
31-
* @psalm-param \Closure(string $indentation, string $propertyName): string $renderFunction
31+
* @param \Closure(string $indentation, string $propertyName): string $renderFunction
3232
*/
3333
public static function fromRenderer($renderFunction): self
3434
{

Classes/Domain/TemplateConfiguration/EelEvaluationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class EelEvaluationService
2828
/**
2929
* Evaluate an Eel expression.
3030
*
31-
* @param $contextVariables array<string, mixed> additional context for eel expressions
31+
* @param array<string, mixed> $contextVariables additional context for eel expressions
3232
* @return mixed The result of the evaluated Eel expression
3333
* @throws ParserException|\Exception
3434
*/

Classes/Domain/TemplateConfiguration/TemplateConfigurationProcessor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TemplateConfigurationProcessor
2323
protected $eelEvaluationService;
2424

2525
/**
26-
* @psalm-param array<string, mixed> $configuration
27-
* @psalm-param array<string, mixed> $evaluationContext
26+
* @param array<string, mixed> $configuration
27+
* @param array<string, mixed> $evaluationContext
2828
* @param ProcessingErrors $caughtEvaluationExceptions
2929
* @return RootTemplate
3030
*/
@@ -145,9 +145,9 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
145145
}
146146

147147
/**
148-
* @psalm-param mixed $rawConfigurationValue
149-
* @psalm-param array<string, mixed> $evaluationContext
150-
* @psalm-return mixed
148+
* @param mixed $rawConfigurationValue
149+
* @param array<string, mixed> $evaluationContext
150+
* @return mixed
151151
* @throws \Neos\Eel\ParserException|\Exception
152152
*/
153153
private function preprocessConfigurationValue($rawConfigurationValue, array $evaluationContext)

Classes/Domain/TemplateConfiguration/TemplatePart.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TemplatePart
3030

3131
/**
3232
* @psalm-readonly
33-
* @psalm-var \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed
33+
* @var \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed
3434
*/
3535
private \Closure $configurationValueProcessor;
3636

@@ -40,9 +40,9 @@ class TemplatePart
4040
private ProcessingErrors $processingErrors;
4141

4242
/**
43-
* @psalm-param array<string, mixed> $configuration
44-
* @psalm-param array<string, mixed> $evaluationContext
45-
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
43+
* @param array<string, mixed> $configuration
44+
* @param array<string, mixed> $evaluationContext
45+
* @param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
4646
* @throws StopBuildingTemplatePartException
4747
*/
4848
private function __construct(
@@ -61,9 +61,9 @@ private function __construct(
6161
}
6262

6363
/**
64-
* @psalm-param array<string, mixed> $configuration
65-
* @psalm-param array<string, mixed> $evaluationContext
66-
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
64+
* @param array<string, mixed> $configuration
65+
* @param array<string, mixed> $evaluationContext
66+
* @param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
6767
* @throws StopBuildingTemplatePartException
6868
*/
6969
public static function createRoot(
@@ -102,7 +102,7 @@ public function getFullPathToConfiguration(): array
102102
}
103103

104104
/**
105-
* @psalm-param string|list<string> $configurationPath
105+
* @param string|list<string> $configurationPath
106106
* @throws StopBuildingTemplatePartException
107107
*/
108108
public function withConfigurationByConfigurationPath($configurationPath): self
@@ -117,7 +117,7 @@ public function withConfigurationByConfigurationPath($configurationPath): self
117117
}
118118

119119
/**
120-
* @psalm-param array<string, mixed> $evaluationContext
120+
* @param array<string, mixed> $evaluationContext
121121
*/
122122
public function withMergedEvaluationContext(array $evaluationContext): self
123123
{
@@ -134,7 +134,7 @@ public function withMergedEvaluationContext(array $evaluationContext): self
134134
}
135135

136136
/**
137-
* @psalm-param string|list<string> $configurationPath
137+
* @param string|list<string> $configurationPath
138138
* @return mixed
139139
* @throws StopBuildingTemplatePartException
140140
*/
@@ -185,7 +185,7 @@ public function getRawConfiguration($configurationPath)
185185
}
186186

187187
/**
188-
* @psalm-param string|list<string> $configurationPath
188+
* @param string|list<string> $configurationPath
189189
*/
190190
public function hasConfiguration($configurationPath): bool
191191
{

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Neos Node Templates
22

3-
When using Neos CMS as an editor, you often work with nested node structures that
3+
When using Neos CMS as an editor, you often work with nested node structures that
44
have to be created manually. This packages aims at easing the editing workflow by
5-
automatically creating helpful child nodes and making useful modifications to node
5+
automatically creating helpful child nodes and making useful modifications to node
66
properties when creating new nodes in the Neos UI.
77

88
In contrast to child nodes that are defined in the regular node type definition
9-
(which cannot be removed by the editor), all modifications that are made when a
9+
(which cannot be removed by the editor), all modifications that are made when a
1010
template is applied can be changed or removed by the editor.
1111

1212
The desired node structure is defined in a declarative way in the NodeTypes.yaml
@@ -89,7 +89,7 @@ You can also access data from the node creation dialog if you use the
8989
ui:
9090
showInCreationDialog: true
9191
'cardTitle':
92-
type: string:
92+
type: string
9393
label: 'Card Title'
9494
options:
9595
template:
@@ -129,7 +129,7 @@ templates) from being applied, its most common use case is conditional child nod
129129
### Loops
130130

131131
Loops can be used to create multiple child nodes. You can use ``withItems`` to define the items
132-
of the loop. When using EEL, be sure to return an array. The current item is available in EEL
132+
of the loop. When using EEL, be sure to return an array. The current item is available in EEL
133133
expressions as the ``item`` context variable.
134134

135135
The following example creates three different text child nodes in the main content collection:
@@ -259,17 +259,22 @@ My.NodeType:Bar (depends on "data" context)
259259

260260
The standalone validation should detect errors and prevents editors having to deal with these errors at runtime.
261261

262-
For more complex templates, which are dependent on the node creation data, it is recommended to write separate tests. Currently, errors in templates depending on the data context will only be treated as warning, as they are probably not an issue at runtime.
262+
For more complex templates, which are dependent on the node creation data, it is recommended to write separate tests. Currently, errors in templates depending on the data context will only be treated as warning, as they are probably not an issue at runtime.
263263

264264
## Create template from node subtree
265265

266266
When creating a more complex node template (to create multiple pages and content elements) it can be helpful to take the current node subtree from your workspace as reference.
267267
For this case you can use the command:
268268

269269
```sh
270-
flow nodeTemplate:createFromNodeSubtree <nodeIdentifier>
270+
flow nodeTemplate:createFromNodeSubtree <starting node id>
271271
```
272272

273+
- `--starting-node-id`: specified root node of the node tree
274+
275+
**options:**
276+
- `--workspace-name`: custom workspace to dump from. Defaults to 'live'.
277+
273278
It will give you the output similar to the yaml example above.
274279
References to Nodes and non-primitive property values are commented out in the YAML.
275280

Tests/Functional/AbstractNodeTemplateTestCase.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Neos\ContentRepository\Domain\Model\Workspace;
1212
use Neos\ContentRepository\Domain\Repository\ContentDimensionRepository;
1313
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
14-
use Neos\ContentRepository\Domain\Service\Context;
1514
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
1615
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
1716
use Neos\Flow\Tests\FunctionalTestCase;
@@ -43,10 +42,11 @@ abstract class AbstractNodeTemplateTestCase extends FunctionalTestCase
4342

4443
private NodeTypeManager $nodeTypeManager;
4544

46-
private Context $subgraph;
47-
4845
private string $fixturesDir;
4946

47+
/** @deprecated please use {@see self::getObject()} instead */
48+
protected $objectManager;
49+
5050
public function setUp(): void
5151
{
5252
parent::setUp();
@@ -82,6 +82,17 @@ public function tearDown(): void
8282
$this->objectManager->forgetInstance(NodeTypeManager::class);
8383
}
8484

85+
/**
86+
* @template T of object
87+
* @param class-string<T> $className
88+
*
89+
* @return T
90+
*/
91+
final protected function getObject(string $className): object
92+
{
93+
return $this->objectManager->get($className);
94+
}
95+
8596
private function setupContentRepository(): void
8697
{
8798
// Create an environment to create nodes.
@@ -98,10 +109,9 @@ private function setupContentRepository(): void
98109

99110
$this->persistenceManager->persistAll();
100111
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
101-
$this->subgraph = $this->contextFactory->create(['workspaceName' => 'live']);
102-
103-
$rootNode = $this->subgraph->getRootNode();
112+
$subgraph = $this->contextFactory->create(['workspaceName' => 'live']);
104113

114+
$rootNode = $subgraph->getRootNode();
105115

106116
$sitesRootNode = $rootNode->createNode('sites');
107117
$testSiteNode = $sitesRootNode->createNode('test-site');

Tests/Functional/FakeNodeTypeManagerTrait.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66

77
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
88
use Neos\Flow\Configuration\ConfigurationManager;
9-
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
109
use Neos\Utility\Arrays;
1110
use Symfony\Component\Yaml\Yaml;
1211

1312
/**
14-
* @property ObjectManagerInterface $objectManager
1513
* @property NodeTypeManager $nodeTypeManager
1614
*/
1715
trait FakeNodeTypeManagerTrait
1816
{
17+
/**
18+
* @template T of object
19+
* @param class-string<T> $className
20+
*
21+
* @return T
22+
*/
23+
abstract protected function getObject(string $className): object;
24+
1925
private function loadFakeNodeTypes(): void
2026
{
21-
$configuration = $this->objectManager->get(ConfigurationManager::class)->getConfiguration('NodeTypes');
27+
$configuration = $this->getObject(ConfigurationManager::class)->getConfiguration('NodeTypes');
2228

2329
$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/Features'));
2430

Tests/Functional/Features/Exceptions/ExceptionsTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ public function exceptionsAreCaughtAndPartialTemplateIsNotBuild(): void
4848

4949
$this->assertLastCreatedTemplateMatchesSnapshot('OnlyExceptions');
5050

51-
// self::assertSame([
52-
// [
53-
// 'message' => 'Template for "WithOneEvaluationException" was not applied. Only Node /sites/test-site/homepage/main/new-node@live[Flowpack.NodeTemplates:Content.WithOneEvaluationException] was created.',
54-
// 'severity' => 'ERROR'
55-
// ],
56-
// [
57-
// 'message' => '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)',
58-
// 'severity' => 'ERROR'
59-
// ]
60-
// ], $this->getMessagesOfFeedbackCollection());
61-
62-
6351
$this->assertCaughtExceptionsMatchesSnapshot('OnlyExceptions');
6452
$this->assertNodeDumpAndTemplateDumpMatchSnapshot('OnlyExceptions', $createdNode);
6553
});

Tests/Functional/Features/ResolvableProperties/ResolvablePropertiesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public function itMatchesSnapshot1(): void
2020
$this->createFakeNode('some-node-id');
2121
$this->createFakeNode('other-node-id');
2222

23-
$resource = $this->objectManager->get(ResourceManager::class)->importResource(__DIR__ . '/image.png');
23+
$resource = $this->getObject(ResourceManager::class)->importResource(__DIR__ . '/image.png');
2424

2525
$asset = new Asset($resource);
2626
ObjectAccess::setProperty($asset, 'Persistence_Object_Identifier', 'c228200e-7472-4290-9936-4454a5b5692a', true);
27-
$this->objectManager->get(AssetRepository::class)->add($asset);
27+
$this->getObject(AssetRepository::class)->add($asset);
2828

29-
$resource2 = $this->objectManager->get(ResourceManager::class)->importResource(__DIR__ . '/image.png');
29+
$resource2 = $this->getObject(ResourceManager::class)->importResource(__DIR__ . '/image.png');
3030

3131
$image = new Image($resource2);
3232
ObjectAccess::setProperty($image, 'Persistence_Object_Identifier', 'c8ae9f9f-dd11-4373-bf42-4bf31ec5bd19', true);
33-
$this->objectManager->get(ImageRepository::class)->add($image);
33+
$this->getObject(ImageRepository::class)->add($image);
3434

3535
$createdNode = $this->createNodeInto(
3636
$this->homePageMainContentCollectionNode,

0 commit comments

Comments
 (0)