Skip to content

Commit

Permalink
TASK: Improve error of exception message by using node labels instead…
Browse files Browse the repository at this point in the history
… of their name and id

 No content collection of type Neos.Neos:ContentCollection could be found in the current node (/Neos.Neos:Sites/Home) or at the path "teaser"
  • Loading branch information
mhsdesign committed Oct 14, 2024
1 parent 688ba82 commit 5901adc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ private function getDelegatedGenerator(?NodeType $nodeType): NodeLabelGeneratorI
public function getLabel(Node $node): string
{
return sprintf(
'%s %s',
'%s%s',
$node->nodeTypeName->value,
$node->name
? sprintf('(%s)', $node->name->value)
? sprintf(' (%s)', $node->name->value)
: ''
);
}
Expand Down
19 changes: 11 additions & 8 deletions Neos.Neos/Classes/Fusion/Helper/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,17 @@ public function nearestContentCollection(Node $node, ?string $nodePath): Node
return $node;
} else {
if ($nodePath === null || $nodePath === '') {
$nodePathOfNode = VisualNodePath::buildFromAncestors(
$node,
$this->contentRepositoryRegistry->get($node->contentRepositoryId),
$this->nodeLabelGenerator
);
throw new Exception(sprintf(
'No content collection of type %s could be found in the current node and no node path was provided.'
'No content collection of type %s could be found in the current node (%s) and no node path was provided.'
. ' You might want to configure the nodePath property'
. ' with a relative path to the content collection.',
$contentCollectionType
$contentCollectionType,
$nodePathOfNode->value
), 1409300545);
}
$nodePath = NodePath::fromString($nodePath);
Expand All @@ -173,13 +179,10 @@ public function nearestContentCollection(Node $node, ?string $nodePath): Node
if ($subNode !== null && $this->isOfType($subNode, $contentCollectionType)) {
return $subNode;
} else {
$nodePathOfNode = VisualNodePath::fromAncestors(
$nodePathOfNode = VisualNodePath::buildFromAncestors(
$node,
$this->contentRepositoryRegistry->subgraphForNode($node)
->findAncestorNodes(
$node->aggregateId,
FindAncestorNodesFilter::create()
)
$this->contentRepositoryRegistry->get($node->contentRepositoryId),
$this->nodeLabelGenerator
);
throw new Exception(sprintf(
'No content collection of type %s could be found in the current node (%s) or at the path "%s".'
Expand Down
25 changes: 20 additions & 5 deletions Neos.Neos/Classes/Presentation/VisualNodePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

namespace Neos\Neos\Presentation;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;

/**
* The string-based visual node path, composed of node names and node aggregate IDs as fallback
* The string-based visual node path
*
* @internal helper for enriched debug information
*/
final readonly class VisualNodePath
{
Expand All @@ -27,13 +32,23 @@ private function __construct(
) {
}

public static function fromAncestors(Node $leafNode, Nodes $ancestors): self
public static function buildFromNodes(Nodes $nodes, NodeLabelGeneratorInterface $nodeLabelGenerator): self
{
$pathSegments = [];
foreach ($ancestors->reverse() as $ancestor) {
$pathSegments[] = $ancestor->name?->value ?: '[' . $ancestor->aggregateId->value . ']';
foreach ($nodes as $node) {
$pathSegments[] = $nodeLabelGenerator->getLabel($node);
}

return new self('/' . implode('/', $pathSegments));
}

public static function buildFromAncestors(Node $startingNode, ContentRepository $contentRepository, NodeLabelGeneratorInterface $nodeLabelGenerator): self
{
$nodes = $contentRepository->getContentGraph($startingNode->workspaceName)
->getSubgraph($startingNode->dimensionSpacePoint, $startingNode->visibilityConstraints)
->findAncestorNodes(
$startingNode->aggregateId,
FindAncestorNodesFilter::create()
)->reverse()->append($startingNode);
return self::buildFromNodes($nodes, $nodeLabelGenerator);
}
}

0 comments on commit 5901adc

Please sign in to comment.