From 576f54cc44c048b035ebd86050effc381fff007f Mon Sep 17 00:00:00 2001 From: Dominique Feyer Date: Thu, 19 May 2016 16:28:58 +0200 Subject: [PATCH] FEATURE: Add custom label for auto created child node This change add a node type configuration to generate a custom node label for auto created child nodes: 'TYPO3.Neos.NodeTypes:Page': superTypes: 'TYPO3.Neos:Document': TRUE childNodes: main: label: "${'Main Content Collection'}" type: 'TYPO3.Neos:ContentCollection' This allow to have a less technical content tree. This change include the schema validation and default label for default node types. The label is an EEL expression, like the normal node label. Inside the expression you can access the parent node in the variable ```parentNode```. --- .../Configuration/NodeTypes.Content.yaml | 13 +++++++++-- .../Configuration/NodeTypes.Documents.yaml | 1 + .../ExpressionBasedNodeLabelGenerator.php | 23 ++++++++++++++++--- .../Private/Schema/NodeTypes.schema.yaml | 1 + 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Content.yaml b/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Content.yaml index 17fd55d2d2d..03ad49e3dd2 100755 --- a/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Content.yaml +++ b/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Content.yaml @@ -181,8 +181,10 @@ position: 200 childNodes: column0: + label: "${'Left Column'}" type: 'TYPO3.Neos:ContentCollection' column1: + label: "${'Right Column'}" type: 'TYPO3.Neos:ContentCollection' properties: layout: @@ -211,10 +213,13 @@ position: 300 childNodes: column0: + label: "${'Left Column'}" type: 'TYPO3.Neos:ContentCollection' column1: + label: "${'Middle Column'}" type: 'TYPO3.Neos:ContentCollection' column2: + label: "${'Right Column'}" type: 'TYPO3.Neos:ContentCollection' properties: layout: @@ -241,12 +246,16 @@ position: 400 childNodes: column0: + label: "${'Left Column'}" type: 'TYPO3.Neos:ContentCollection' column1: + label: "${'Middle Left Column'}" type: 'TYPO3.Neos:ContentCollection' column2: + label: "${'Middle Right Column'}" type: 'TYPO3.Neos:ContentCollection' - column3: + column2: + label: "${'Right Column'}" type: 'TYPO3.Neos:ContentCollection' properties: layout: @@ -337,4 +346,4 @@ 'TYPO3.Neos.NodeTypes:Records': superTypes: 'TYPO3.Neos.NodeTypes:ContentReferences': TRUE - abstract: TRUE \ No newline at end of file + abstract: TRUE diff --git a/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Documents.yaml b/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Documents.yaml index 8691bbdeb23..afda52a726f 100755 --- a/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Documents.yaml +++ b/TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Documents.yaml @@ -3,6 +3,7 @@ 'TYPO3.Neos:Document': TRUE childNodes: main: + label: "${'Main Content Collection'}" type: 'TYPO3.Neos:ContentCollection' properties: layout: diff --git a/TYPO3.TYPO3CR/Classes/TYPO3/TYPO3CR/Domain/Model/ExpressionBasedNodeLabelGenerator.php b/TYPO3.TYPO3CR/Classes/TYPO3/TYPO3CR/Domain/Model/ExpressionBasedNodeLabelGenerator.php index 94b4e3bd1c7..74c7b958c53 100644 --- a/TYPO3.TYPO3CR/Classes/TYPO3/TYPO3CR/Domain/Model/ExpressionBasedNodeLabelGenerator.php +++ b/TYPO3.TYPO3CR/Classes/TYPO3/TYPO3CR/Domain/Model/ExpressionBasedNodeLabelGenerator.php @@ -11,7 +11,10 @@ * source code. */ +use TYPO3\Eel\Utility; use TYPO3\Flow\Annotations as Flow; +use TYPO3\Flow\Object\DependencyInjection\DependencyProxy; +use TYPO3\Flow\Utility\Unicode\Functions; /** * The expression based node label generator that is used as default if a label expression is configured. @@ -57,7 +60,7 @@ public function setExpression($expression) */ public function initializeObject() { - if ($this->eelEvaluator instanceof \TYPO3\Flow\Object\DependencyInjection\DependencyProxy) { + if ($this->eelEvaluator instanceof DependencyProxy) { $this->eelEvaluator->_activateDependency(); } } @@ -71,13 +74,27 @@ public function initializeObject() */ public function getLabel(NodeInterface $node, $crop = true) { - $label = \TYPO3\Eel\Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, array('node' => $node), $this->defaultContextConfiguration); + $label = null; + if ($node->getNodeType()->isOfType('TYPO3.Neos:ContentCollection') && $node->isAutoCreated()) { + $parentNode = $node->getParent(); + $property = 'childNodes.' . $node->getName() . '.label'; + if ($parentNode->getNodeType()->hasConfiguration($property)) { + $expression = $parentNode->getNodeType()->getConfiguration($property); + $label = Utility::evaluateEelExpression($expression, $this->eelEvaluator, [ + 'node' => $node, + 'parentNode' => $parentNode + ], $this->defaultContextConfiguration);; + } + } + if ($label === null) { + $label = Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration); + } if ($crop === false) { return $label; } - $croppedLabel = \TYPO3\Flow\Utility\Unicode\Functions::substr($label, 0, 30); + $croppedLabel = Functions::substr($label, 0, 30); return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : ''); } } diff --git a/TYPO3.TYPO3CR/Resources/Private/Schema/NodeTypes.schema.yaml b/TYPO3.TYPO3CR/Resources/Private/Schema/NodeTypes.schema.yaml index 0393989e682..af86d0f7527 100644 --- a/TYPO3.TYPO3CR/Resources/Private/Schema/NodeTypes.schema.yaml +++ b/TYPO3.TYPO3CR/Resources/Private/Schema/NodeTypes.schema.yaml @@ -38,6 +38,7 @@ additionalProperties: type: dictionary additionalProperties: FALSE properties: + 'label': { type: string, description: "Human-readable label for this child node." } 'type': { type: string, description: "Node Type of this child node." } 'position': type: ['string', 'null']