Skip to content

Commit

Permalink
TASK: Adjust to changed node path API (#3530)
Browse files Browse the repository at this point in the history
* Adjust to changed node path API

* Adjust to findAncestorNodes query

---------

Co-authored-by: Bernhard Schmitt <[email protected]>
  • Loading branch information
nezaniel and Bernhard Schmitt authored Jul 7, 2023
1 parent da37c21 commit bc6569f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
30 changes: 12 additions & 18 deletions Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -108,7 +99,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments)
$baseNodeTypeConstraints,
$loadingDepth,
$toggledNodes,
$parents,
$ancestors,
$subgraph,
$nodeAddressFactory,
$contentRepository
Expand All @@ -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,
Expand Down
23 changes: 12 additions & 11 deletions Classes/Fusion/Helper/NodeInfoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bc6569f

Please sign in to comment.