Skip to content

Commit 26ef0fb

Browse files
authored
Merge pull request #5667 from bijusk/sprint-i18n-childnodes
BUGFIX: Translate label for childNodes
2 parents 1f9601c + 26b98ab commit 26ef0fb

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Neos.ContentRepository/Classes/Domain/Model/ExpressionBasedNodeLabelGenerator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Neos\Eel\EelEvaluatorInterface;
1515
use Neos\Eel\Utility;
1616
use Neos\Flow\Annotations as Flow;
17+
use Neos\Flow\I18n\EelHelper\TranslationHelper;
1718
use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy;
1819

1920
/**
@@ -34,6 +35,12 @@ class ExpressionBasedNodeLabelGenerator implements NodeLabelGeneratorInterface
3435
*/
3536
protected $defaultContextConfiguration;
3637

38+
/**
39+
* @Flow\Inject
40+
* @var TranslationHelper
41+
*/
42+
protected $translationHelper;
43+
3744
/**
3845
* @var string
3946
*/
@@ -73,14 +80,19 @@ public function initializeObject()
7380
public function getLabel(\Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node): string
7481
{
7582
$expression = $this->getExpression();
83+
7684
if ($node->isAutoCreated()) {
7785
$parentNode = $node->getParent();
7886
$property = 'childNodes.' . $node->getName() . '.label';
7987
if ($parentNode?->getNodeType()->hasConfiguration($property)) {
8088
$expression = $parentNode->getNodeType()->getConfiguration($property);
8189
}
8290
}
91+
8392
if (Utility::parseEelExpression($expression) === null) {
93+
if ($node->isAutoCreated()) {
94+
return $this->translationHelper->translate($expression);
95+
}
8496
return $expression;
8597
}
8698
return (string)Utility::evaluateEelExpression($expression, $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);

Neos.Neos/Classes/Aspects/NodeTypeConfigurationEnrichmentAspect.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function enrichNodeTypeLabelsConfiguration(JoinPointInterface $joinPoint)
5757
$declaredSuperTypes = $joinPoint->getMethodArgument('declaredSuperTypes');
5858
$configuration = $joinPoint->getMethodArgument('configuration');
5959
$nodeTypeName = $joinPoint->getMethodArgument('name');
60-
6160
$this->addLabelsToNodeTypeConfiguration($nodeTypeName, $configuration, $declaredSuperTypes);
62-
6361
$joinPoint->setMethodArgument('configuration', $configuration);
6462
$joinPoint->getAdviceChain()->proceed($joinPoint);
6563
}
@@ -79,6 +77,26 @@ protected function addLabelsToNodeTypeConfiguration($nodeTypeName, array &$confi
7977
if (isset($configuration['properties'])) {
8078
$this->setPropertyLabels($nodeTypeName, $configuration, $declaredSuperTypes);
8179
}
80+
81+
if (isset($configuration['childNodes'])) {
82+
$this->setChildNodeLabels($nodeTypeName, $configuration);
83+
}
84+
}
85+
86+
87+
/**
88+
* @param string $nodeTypeName
89+
* @param array $configuration
90+
* @return void
91+
*/
92+
protected function setChildNodeLabels(string $nodeTypeName, array &$configuration)
93+
{
94+
$nodeTypeLabelIdPrefix = $this->generateNodeTypeLabelIdPrefix($nodeTypeName);
95+
foreach ($configuration['childNodes'] as $childNodeName => &$childNodeConfiguration) {
96+
if ($childNodeConfiguration && $this->shouldFetchTranslation($childNodeConfiguration)) {
97+
$childNodeConfiguration['label'] = $this->getChildNodeLabelTranslationId($nodeTypeLabelIdPrefix, $childNodeName);
98+
}
99+
}
82100
}
83101

84102
/**
@@ -300,6 +318,18 @@ protected function getPropertyLabelTranslationId($nodeTypeSpecificPrefix, $prope
300318
return $nodeTypeSpecificPrefix . 'properties.' . $propertyName;
301319
}
302320

321+
/**
322+
* Generates a childNode label with the given $nodeTypeSpecificPrefix.
323+
*
324+
* @param string $nodeTypeSpecificPrefix
325+
* @param string $childNodeName
326+
* @return string
327+
*/
328+
protected function getChildNodeLabelTranslationId(string $nodeTypeSpecificPrefix, string $childNodeName)
329+
{
330+
return $nodeTypeSpecificPrefix . 'childNodes.' . $childNodeName;
331+
}
332+
303333
/**
304334
* Generates a property configuration-label with the given $nodeTypeSpecificPrefix.
305335
*

0 commit comments

Comments
 (0)