Skip to content

Commit

Permalink
Merge pull request #4083 from neos/feature/allow-non-eel-labels
Browse files Browse the repository at this point in the history
FEATURE: Allow non eel labels in nodetypes
  • Loading branch information
Sebobo committed Mar 19, 2023
2 parents 7fa4fc6 + 54bae63 commit 4fb1589
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Expand Up @@ -66,14 +66,17 @@ public function initializeObject()
}

/**
* Render a node label
* 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();
}
return (string)Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
}
}
6 changes: 6 additions & 0 deletions Neos.ContentRepository/Configuration/Testing/NodeTypes.yaml
Expand Up @@ -199,3 +199,9 @@
type: string
someDate:
type: DateTime

'Neos.ContentRepository.Testing:NodeTypeWithPlainLabel':
label: 'Test nodetype'

'Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabel':
label: '${"Test" + " " + "nodetype"}'
17 changes: 17 additions & 0 deletions Neos.ContentRepository/Tests/Functional/Domain/NodesTest.php
Expand Up @@ -1060,6 +1060,23 @@ public function getLabelUsesFallbackExpression()
self::assertEquals('unstructured ()', $node->getLabel());
}

/**
* @test
*/
public function getLabelReturnsParsedEelExpressionOrFallback()
{
$nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
$nodeTypeWithPlainLabel = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithPlainLabel');
$nodeTypeWithEelExpressionLabel = $nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithEelExpressionLabel');

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

self::assertEquals('Test nodetype', $nodeWithPlainLabel->getLabel());
self::assertEquals('Test nodetype', $nodeWithEelExpressionLabel->getLabel());
}

/**
* @test
*/
Expand Down
Expand Up @@ -371,7 +371,7 @@ function ($name) {

self::assertEquals('unstructured', $this->nodeData->getNodeType()->getName());

$myNodeType = $mockNodeTypeManager->getNodeType('typo3:mycontent');
$myNodeType = $mockNodeTypeManager->getNodeType('neos:mycontent');
$this->nodeData->setNodeType($myNodeType);
self::assertEquals($myNodeType, $this->nodeData->getNodeType());
}
Expand Down

0 comments on commit 4fb1589

Please sign in to comment.