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:

    ‚Neos.NodeTypes:Page':
      superTypes:
        ‚Neos.Neos:Document': TRUE
      childNodes:
        main:
          label: ‚Main Content Collection'
          type: ‚Neos.Neos:ContentCollection'

This allow to have a less technical content tree. This change include the
schema validation and default label for default node types.
  • Loading branch information
dfeyer authored and Sebobo committed Jul 27, 2024
1 parent 013538b commit 3b9ec37
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 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
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 All @@ -63,7 +64,6 @@ additionalProperties:

'type': { type: string, description: "PHP type of this property. Either simple type or fully qualified PHP class name." }
'defaultValue': { type: any, description: "Default value of this property. Used at node creation time. Type must match specified 'type'." }
'position': { type: ['string', 'number', 'null'] }

'validation':
type: ['dictionary', 'null']
Expand Down Expand Up @@ -106,7 +106,6 @@ additionalProperties:
type: dictionary
additionalProperties: false
properties:
'postprocessor': { type: string, format: class-name, required: true }
'position': { type: ['string', 'number', 'null'] }
'postprocessor': { type: string, format: class-name, required: TRUE }
'postprocessorOptions':
type: dictionary
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 3b9ec37

Please sign in to comment.