Skip to content

Commit

Permalink
FEATURE: Add custom label for auto created child node
Browse files Browse the repository at this point in the history
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```.
  • Loading branch information
dfeyer committed May 19, 2016
1 parent 4f2d77e commit 576f54c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
13 changes: 11 additions & 2 deletions TYPO3.Neos.NodeTypes/Configuration/NodeTypes.Content.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -337,4 +346,4 @@
'TYPO3.Neos.NodeTypes:Records':
superTypes:
'TYPO3.Neos.NodeTypes:ContentReferences': TRUE
abstract: TRUE
abstract: TRUE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'TYPO3.Neos:Document': TRUE
childNodes:
main:
label: "${'Main Content Collection'}"
type: 'TYPO3.Neos:ContentCollection'
properties:
layout:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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) ? '' : '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 576f54c

Please sign in to comment.