From bc6569fd04180e650d98f8f1c7d3d214593e951d Mon Sep 17 00:00:00 2001 From: Bernhard Schmitt Date: Fri, 7 Jul 2023 10:16:18 +0200 Subject: [PATCH] TASK: Adjust to changed node path API (#3530) * Adjust to changed node path API * Adjust to findAncestorNodes query --------- Co-authored-by: Bernhard Schmitt --- .../NeosUiDefaultNodesOperation.php | 30 ++++++++----------- Classes/Fusion/Helper/NodeInfoHelper.php | 23 +++++++------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php b/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php index 5c53dc7a3f..4d80cd82b4 100644 --- a/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php +++ b/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php @@ -12,9 +12,9 @@ * source code. */ +use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; -use Neos\ContentRepository\Core\NodeType\NodeTypeConstraintParser; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\FlowQuery\FlowQuery; @@ -79,21 +79,12 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) $subgraph = $this->contentRepositoryRegistry->subgraphForNode($documentNode); - // Collect all parents of documentNode up to siteNode - $parents = []; - $currentNode = $subgraph->findParentNode($documentNode->nodeAggregateId); - if ($currentNode) { - $currentNodePath = $subgraph->retrieveNodePath($currentNode->nodeAggregateId); - $siteNodePath = $subgraph->retrieveNodePath($siteNode->nodeAggregateId); - $parentNodeIsUnderneathSiteNode = str_starts_with($currentNodePath->value, $siteNodePath->value); - while ($currentNode instanceof Node - && !$currentNode->nodeAggregateId->equals($siteNode->nodeAggregateId) - && $parentNodeIsUnderneathSiteNode - ) { - $parents[] = $currentNode->nodeAggregateId->jsonSerialize(); - $currentNode = $subgraph->findParentNode($currentNode->nodeAggregateId); - } - } + $ancestors = $subgraph->findAncestorNodes( + $documentNode->nodeAggregateId, + FindAncestorNodesFilter::create( + NodeTypeConstraints::fromFilterString('Neos.Neos:Document') + ) + ); $nodes = [ ($siteNode->nodeAggregateId->value) => $siteNode @@ -108,7 +99,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) $baseNodeTypeConstraints, $loadingDepth, $toggledNodes, - $parents, + $ancestors, $subgraph, $nodeAddressFactory, $contentRepository @@ -120,7 +111,10 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) // load toggled nodes in_array($baseNodeAddress->serializeForUri(), $toggledNodes) || // load children of all parents of documentNode - in_array($baseNode->nodeAggregateId->value, $parents) + in_array($baseNode->nodeAggregateId->value, array_map( + fn (Node $node): string => $node->nodeAggregateId->value, + iterator_to_array($ancestors) + )) ) { foreach ($subgraph->findChildNodes( $baseNode->nodeAggregateId, diff --git a/Classes/Fusion/Helper/NodeInfoHelper.php b/Classes/Fusion/Helper/NodeInfoHelper.php index 1122c27f7d..d85ac50063 100644 --- a/Classes/Fusion/Helper/NodeInfoHelper.php +++ b/Classes/Fusion/Helper/NodeInfoHelper.php @@ -12,6 +12,7 @@ */ use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\CountAncestorNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes; @@ -237,7 +238,10 @@ protected function getBasicNodeInformation(Node $node): array 'label' => $node->getLabel(), 'isAutoCreated' => self::isAutoCreated($node, $subgraph), // TODO: depth is expensive to calculate; maybe let's get rid of this? - 'depth' => $subgraph->retrieveNodePath($node->nodeAggregateId)->getDepth(), + 'depth' => $subgraph->countAncestorNodes( + $node->nodeAggregateId, + CountAncestorNodesFilter::create() + ), 'children' => [], 'parent' => $parentNode ? $nodeAddressFactory->createFromNode($parentNode)->serializeForUri() : null, 'matchesCurrentDimensions' => $node->subgraphIdentity->dimensionSpacePoint->equals($node->originDimensionSpacePoint), @@ -328,16 +332,15 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll foreach ($nodes as $node) { $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); - $nodePath = $subgraph->retrieveNodePath($node->nodeAggregateId); - if (array_key_exists($nodePath->value, $renderedNodes)) { - $renderedNodes[$nodePath->value]['matched'] = true; + if (array_key_exists($node->nodeAggregateId->value, $renderedNodes)) { + $renderedNodes[$node->nodeAggregateId->value]['matched'] = true; } elseif ($renderedNode = $this->renderNodeWithMinimalPropertiesAndChildrenInformation( $node, $controllerContext, $baseNodeTypeOverride )) { $renderedNode['matched'] = true; - $renderedNodes[$nodePath->value] = $renderedNode; + $renderedNodes[$node->nodeAggregateId->value] = $renderedNode; } else { continue; } @@ -349,10 +352,9 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll continue; } - $parentNodePath = $subgraph->retrieveNodePath($parentNode->nodeAggregateId); while ($parentNode->nodeType->isOfType($baseNodeTypeOverride)) { - if (array_key_exists($parentNodePath->value, $renderedNodes)) { - $renderedNodes[$parentNodePath->value]['intermediate'] = true; + if (array_key_exists($parentNode->nodeAggregateId->value, $renderedNodes)) { + $renderedNodes[$parentNode->nodeAggregateId->value]['intermediate'] = true; } else { $renderedParentNode = $this->renderNodeWithMinimalPropertiesAndChildrenInformation( $parentNode, @@ -361,7 +363,7 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll ); if ($renderedParentNode) { $renderedParentNode['intermediate'] = true; - $renderedNodes[$parentNodePath->value] = $renderedParentNode; + $renderedNodes[$parentNode->nodeAggregateId->value] = $renderedParentNode; } } $parentNode = $subgraph->findParentNode($parentNode->nodeAggregateId); @@ -401,8 +403,7 @@ protected function renderNodeAndChildContent(Node $node, ControllerContext $cont $nodeAddressFactory = NodeAddressFactory::create($contentRepository); return array_reduce( - $this->getChildNodes($node, $this->buildContentChildNodeFilterString()) - ->getIterator()->getArrayCopy(), + iterator_to_array($this->getChildNodes($node, $this->buildContentChildNodeFilterString())), $reducer, [ $nodeAddressFactory->createFromNode($node)->serializeForUri()