Skip to content

Commit

Permalink
TASK: Introduce NodeLabel value object
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed May 13, 2024
1 parent 14802e8 commit 8482288
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ public function evaluate(FlowQuery $flowQuery, array $arguments)
if (!$node instanceof Node) {
return null;
}
return $this->nodeLabelRenderer->renderNodeLabel($node);
return $this->nodeLabelRenderer->renderNodeLabel($node)->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ public function setExpression(string $expression): void
* Render a node label based on an eel expression or return the expression if it is not valid eel.
* @throws \Neos\Eel\Exception
*/
public function getLabel(Node $node): string
public function getLabel(Node $node): NodeLabel
{
if (Utility::parseEelExpression($this->getExpression()) === null) {
return $this->getExpression();
return NodeLabel::fromString($this->getExpression());
}
return (string)Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
$value = Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
return NodeLabel::fromString((string)$value);
}
}
18 changes: 18 additions & 0 deletions Neos.Neos/Classes/Domain/NodeLabel/NodeLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Neos\Neos\Domain\NodeLabel;

final readonly class NodeLabel
{
private function __construct(
public string $value
) {
}

public static function fromString(string $value): self
{
return new self($value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface NodeLabelGeneratorInterface
* Render a node label
* @api
*/
public function getLabel(Node $node): string;
public function getLabel(Node $node): NodeLabel;
}
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/Domain/NodeLabel/NodeLabelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
) {
}

public function renderNodeLabel(Node $node): string
public function renderNodeLabel(Node $node): NodeLabel
{
$nodeType = $this->getNodeType($node);
$generator = $this->getNodeLabelGeneratorForNodeType($nodeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/
interface NodeLabelRendererInterface
{
public function renderNodeLabel(Node $node): string;
public function renderNodeLabel(Node $node): NodeLabel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function determineLabel(?Node $variant = null, array $metadata = []):
if ($this->getContentDimensionIdentifierToLimitTo()) {
return $metadata[$this->getContentDimensionIdentifierToLimitTo()->value]['label'] ?: '';
} elseif ($variant) {
return $this->nodeLabelRenderer->renderNodeLabel($variant) ?: '';
return $this->nodeLabelRenderer->renderNodeLabel($variant)->value ?: '';
} else {
return array_reduce($metadata, function ($carry, $item) {
return $carry . (empty($carry) ? '' : '-') . $item['label'];
Expand Down
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/Fusion/MenuItemsImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function buildMenuItemFromNode(Node $node): MenuItem
return new MenuItem(
$node,
$this->isCalculateItemStatesEnabled() ? $this->calculateItemState($node) : null,
$this->nodeLabelRenderer->renderNodeLabel($node),
$this->nodeLabelRenderer->renderNodeLabel($node)->value,
0,
[],
$this->buildUri($node)
Expand All @@ -244,7 +244,7 @@ protected function buildMenuItemFromSubtree(Subtree $subtree, int $startLevel =
return new MenuItem(
$node,
$this->isCalculateItemStatesEnabled() ? $this->calculateItemState($node) : null,
$this->nodeLabelRenderer->renderNodeLabel($node),
$this->nodeLabelRenderer->renderNodeLabel($node)->value,
$subtree->level + $startLevel,
$children,
$this->buildUri($node)
Expand Down
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/Utility/NodeUriPathSegmentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function generateUriPathSegment(?Node $node = null, ?string $text = null)
{
$language = null;
if ($node) {
$text = $text ?: $this->nodeLabelRenderer->renderNodeLabel($node) ?: ($node->nodeName?->value ?? '');
$text = $text ?: $this->nodeLabelRenderer->renderNodeLabel($node)->value ?: ($node->nodeName?->value ?? '');
$languageDimensionValue = $node->originDimensionSpacePoint->coordinates['language'] ?? null;
if (!is_null($languageDimensionValue)) {
$locale = new Locale($languageDimensionValue);
Expand Down
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/ViewHelpers/Link/NodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function render(): string
$this->templateVariableContainer->remove($this->arguments['nodeVariableName']);

if ($content === null && $resolvedNode !== null) {
$content = $this->nodeLabelRenderer->renderNodeLabel($resolvedNode);
$content = $this->nodeLabelRenderer->renderNodeLabel($resolvedNode)->value;
}

$this->tag->setContent($content);
Expand Down

0 comments on commit 8482288

Please sign in to comment.