Skip to content

Commit

Permalink
Merge pull request #530 from dfeyer/feature-custom-child-node-label
Browse files Browse the repository at this point in the history
FEATURE: Custom label for auto created child nodes
  • Loading branch information
Sebobo authored Aug 13, 2024
2 parents 013538b + 7bba496 commit ed79f5f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ public function initializeObject()
/**
* Render a node label based on an eel expression or return the expression if it is not valid eel.
*
* @param \Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node
* @return string
* @throws \Neos\Eel\Exception
*/
public function getLabel(\Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node): string
{
if (Utility::parseEelExpression($this->getExpression()) === null) {
return $this->getExpression();
$expression = $this->getExpression();
if ($node->isAutoCreated()) {
$parentNode = $node->getParent();
$property = 'childNodes.' . $node->getName() . '.label';
if ($parentNode?->getNodeType()->hasConfiguration($property)) {
$expression = $parentNode->getNodeType()->getConfiguration($property);
}
}
if (Utility::parseEelExpression($expression) === null) {
return $expression;
}
return (string)Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
}
Expand Down
10 changes: 10 additions & 0 deletions Neos.ContentRepository/Configuration/Testing/NodeTypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,13 @@

'Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabel':
label: '${"Test" + " " + "nodetype"}'

'Neos.ContentRepository.Testing:NodeTypeWithPlainLabelInChildNode':
childNodes:
child:
label: 'Test child node'

'Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabelInChildNode':
childNodes:
child:
label: '${"Test" + " child " + "node"}'
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ additionalProperties:

'label':
type: ['string', 'array']
description: "An EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional options."
description: "An EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional generator options."

'constraints': &constraints
type: dictionary
Expand All @@ -42,6 +42,7 @@ additionalProperties:
type: dictionary
additionalProperties: false
properties:
'label': { type: string, description: "A string or an EEL expression for generating a node's of this node type's label. Alternatively an array with the key generatorClass and optional generator options." }
'type': { type: string, description: "Node Type of this child node." }
'position':
type: ['string', 'null']
Expand Down
17 changes: 17 additions & 0 deletions Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,23 @@ public function getLabelReturnsParsedEelExpressionOrFallback()
self::assertEquals('Test nodetype', $nodeWithEelExpressionLabel->getLabel());
}

/**
* @test
*/
public function getChildNodeLabelReturnsParsedEelExpressionOrFallback()
{
$nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
$nodeTypeWithPlainLabelInChildNode = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithPlainLabelInChildNode');
$nodeTypeWithEelExpressionLabelInChildNode = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabelInChildNode');

$rootNode = $this->context->getNode('/');
$nodeWithPlainLabelInChildNode = $rootNode->createNode('node-plain', $nodeTypeWithPlainLabelInChildNode, '30e893c1-caef-0ca5-b53d-e5699bb8e506');
$nodeWithEelExpressionLabelInChildNode = $rootNode->createNode('node-eel', $nodeTypeWithEelExpressionLabelInChildNode, '81c848ed-abb5-7608-a5db-7eea0331ccfa');

self::assertEquals('Test child node', $nodeWithPlainLabelInChildNode->getLabel());
self::assertEquals('Test child node', $nodeWithEelExpressionLabelInChildNode->getLabel());
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
position: 400
childNodes:
column0:
label: 'Left Column'
type: 'Neos.Neos:ContentCollection'
column1:
label: 'Middle Left Column'
type: 'Neos.Neos:ContentCollection'
column2:
label: 'Middle Right Column'
type: 'Neos.Neos:ContentCollection'
column3:
label: 'Right Column'
type: 'Neos.Neos:ContentCollection'
properties:
layout:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
position: 300
childNodes:
column0:
label: 'Left Column'
type: 'Neos.Neos:ContentCollection'
column1:
label: 'Middle Column'
type: 'Neos.Neos:ContentCollection'
column2:
label: 'Right Column'
type: 'Neos.Neos:ContentCollection'
properties:
layout:
Expand Down
2 changes: 2 additions & 0 deletions Neos.NodeTypes.ColumnLayouts/NodeTypes/Content/TwoColumn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
position: 200
childNodes:
column0:
label: 'Left Column'
type: 'Neos.Neos:ContentCollection'
column1:
label: 'Right Column'
type: 'Neos.Neos:ContentCollection'
properties:
layout:
Expand Down

0 comments on commit ed79f5f

Please sign in to comment.