Skip to content

Commit 2c0bb09

Browse files
authored
Merge pull request #70 from Flowpack/feature/parentNodeAndDeprecateTriggeringNode
FEATURE: Deprecate `triggeringNode` in favour of `site` and `parentNode`
2 parents a1bbc58 + 72bf900 commit 2c0bb09

File tree

7 files changed

+78
-7
lines changed

7 files changed

+78
-7
lines changed

Classes/Domain/TemplateNodeCreationHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Neos\ContentRepository\Domain\Model\NodeInterface;
1010
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
1111
use Neos\Flow\Annotations as Flow;
12+
use Neos\Neos\Domain\Service\ContentContext;
1213
use Neos\Neos\Ui\NodeCreationHandler\NodeCreationHandlerInterface;
1314

1415
class TemplateNodeCreationHandler implements NodeCreationHandlerInterface
@@ -49,9 +50,15 @@ public function handle(NodeInterface $node, array $data): void
4950
return;
5051
}
5152

53+
/** @var ContentContext $contentContext */
54+
$contentContext = $node->getContext();
55+
5256
$evaluationContext = [
5357
'data' => $data,
58+
// triggeringNode is deprecated and will be removed in 3.0
5459
'triggeringNode' => $node,
60+
'site' => $contentContext->getCurrentSiteNode(),
61+
'parentNode' => $node->getParent(),
5562
];
5663

5764
$templateConfiguration = $node->getNodeType()->getConfiguration('options.template');

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,29 @@ 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 | NodeInterface | 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+
| ~triggeringNode~ | `Node` | _Deprecated:_ The new node itself which is triggering the template processing | Global |
168+
| item | `mixed` | The current item value inside a loop | Inside `withItems` loop |
169+
| key | `string` | The current item key inside a loop | Inside `withItems` loop |
170+
171+
> **Notice**
172+
> `triggeringNode` will be removed with version 3.0
173+
174+
> **Warning**
175+
> The behaviour of `parentNode` changed from version 1.x to version 2.2
176+
> Previously it referenced the parent node of the current template part and its nesting.
177+
> 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.
168178

169179
### Additional context
170180

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

174-
```
184+
```yaml
175185
template:
176186
withContext:
177187
someText: '<p>foo</p>'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# We test that `parentNode` and `site` are accessible in EEL
2+
---
3+
4+
'Flowpack.NodeTemplates:Content.Variables':
5+
superTypes:
6+
'Neos.Neos:Content': true
7+
properties:
8+
text:
9+
type: string
10+
options:
11+
template:
12+
properties:
13+
text: "${'parentNode(' + parentNode.nodeType.name + ', ' + parentNode.name + ') site(' + site.nodeType.name + ', ' + site.name + ')'}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"properties": {
3+
"text": "parentNode(Neos.Neos:ContentCollection, main) site(unstructured, test-site)"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"properties": {
3+
"text": "parentNode(Neos.Neos:ContentCollection, main) site(unstructured, test-site)"
4+
},
5+
"childNodes": []
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'{nodeTypeName}':
2+
options:
3+
template:
4+
properties:
5+
text: 'parentNode(Neos.Neos:ContentCollection, main) site(unstructured, test-site)'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\NodeTemplates\Tests\Functional\Features\Variables;
6+
7+
use Flowpack\NodeTemplates\Tests\Functional\AbstractNodeTemplateTestCase;
8+
9+
class VariablesTest extends AbstractNodeTemplateTestCase
10+
{
11+
/** @test */
12+
public function itMatchesSnapshot(): void
13+
{
14+
$createdNode = $this->createNodeInto(
15+
$this->homePageMainContentCollectionNode,
16+
'Flowpack.NodeTemplates:Content.Variables',
17+
[]
18+
);
19+
20+
$this->assertLastCreatedTemplateMatchesSnapshot('Variables');
21+
22+
$this->assertNoExceptionsWereCaught();
23+
$this->assertNodeDumpAndTemplateDumpMatchSnapshot('Variables', $createdNode);
24+
}
25+
}

0 commit comments

Comments
 (0)