From ac24f7c3146a331b09cf3b52c3d9bc30ac56cb99 Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Sat, 25 May 2024 19:47:23 +0200 Subject: [PATCH 1/4] FEATURE: Find nodes by their id in Neos Backend Extends the custom `SearchOperation` such that it respects node aggregate ids Depends on https://github.com/neos/neos-development-collection/pull/5098 Related: #3771 --- Classes/FlowQueryOperations/SearchOperation.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Classes/FlowQueryOperations/SearchOperation.php b/Classes/FlowQueryOperations/SearchOperation.php index 815380fd2f..b0e5989abd 100644 --- a/Classes/FlowQueryOperations/SearchOperation.php +++ b/Classes/FlowQueryOperations/SearchOperation.php @@ -16,6 +16,7 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\SearchTerm; use Neos\ContentRepository\Core\NodeType\NodeTypeConstraintParser; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\FlowQuery\FlowQuery; @@ -76,17 +77,24 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): void /** @var Node $contextNode */ $contextNode = $context[0]; $subgraph = $this->contentRepositoryRegistry->subgraphForNode($contextNode); + $matchingNodeByAggregateId = []; $filter = FindDescendantNodesFilter::create(); if (isset($arguments[0]) && $arguments[0] !== '') { + if (NodeAggregateId::hasValidFormat($arguments[0])) { + $matchingNodeByAggregateId = $subgraph->findNodeById(NodeAggregateId::fromString($arguments[0])); + } $filter = $filter->with(searchTerm: $arguments[0]); } if (isset($arguments[1]) && $arguments[1] !== '') { $filter = $filter->with(nodeTypes: $arguments[1]); } - $nodes = $subgraph->findDescendantNodes( + $nodes = iterator_to_array($subgraph->findDescendantNodes( $contextNode->aggregateId, $filter - ); - $flowQuery->setContext(iterator_to_array($nodes)); + )); + if ($matchingNodeByAggregateId !== null) { + array_unshift($nodes, $matchingNodeByAggregateId); + } + $flowQuery->setContext($nodes); } } From 9d2d51a2823524bb17fc3b0071a53b83a8065151 Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Sun, 26 May 2024 12:57:49 +0200 Subject: [PATCH 2/4] Adjust to modified NodeAggregateId --- Classes/FlowQueryOperations/SearchOperation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/FlowQueryOperations/SearchOperation.php b/Classes/FlowQueryOperations/SearchOperation.php index b0e5989abd..661424d28c 100644 --- a/Classes/FlowQueryOperations/SearchOperation.php +++ b/Classes/FlowQueryOperations/SearchOperation.php @@ -80,8 +80,8 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): void $matchingNodeByAggregateId = []; $filter = FindDescendantNodesFilter::create(); if (isset($arguments[0]) && $arguments[0] !== '') { - if (NodeAggregateId::hasValidFormat($arguments[0])) { - $matchingNodeByAggregateId = $subgraph->findNodeById(NodeAggregateId::fromString($arguments[0])); + if ($nodeAggregateId = NodeAggregateId::tryFromString($arguments[0])) { + $matchingNodeByAggregateId = $subgraph->findNodeById($nodeAggregateId); } $filter = $filter->with(searchTerm: $arguments[0]); } From 0a6ae5341bf2959948edf74811c2a2d89aad6f73 Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Sun, 26 May 2024 13:59:42 +0200 Subject: [PATCH 3/4] Fix namespace imports --- Classes/FlowQueryOperations/SearchOperation.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Classes/FlowQueryOperations/SearchOperation.php b/Classes/FlowQueryOperations/SearchOperation.php index 661424d28c..edd08f24ad 100644 --- a/Classes/FlowQueryOperations/SearchOperation.php +++ b/Classes/FlowQueryOperations/SearchOperation.php @@ -13,11 +13,7 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; -use Neos\ContentRepository\Core\Projection\ContentGraph\SearchTerm; -use Neos\ContentRepository\Core\NodeType\NodeTypeConstraintParser; -use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; -use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\FlowQuery\FlowQuery; use Neos\Eel\FlowQuery\Operations\AbstractOperation; From 0080f7eb9fc294df52e0b1f8930184cc2c872aba Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Wed, 18 Sep 2024 11:23:13 +0200 Subject: [PATCH 4/4] Update Classes/FlowQueryOperations/SearchOperation.php Co-authored-by: Wilhelm Behncke <2522299+grebaldi@users.noreply.github.com> --- Classes/FlowQueryOperations/SearchOperation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/FlowQueryOperations/SearchOperation.php b/Classes/FlowQueryOperations/SearchOperation.php index edd08f24ad..f57bb5a1ed 100644 --- a/Classes/FlowQueryOperations/SearchOperation.php +++ b/Classes/FlowQueryOperations/SearchOperation.php @@ -73,7 +73,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): void /** @var Node $contextNode */ $contextNode = $context[0]; $subgraph = $this->contentRepositoryRegistry->subgraphForNode($contextNode); - $matchingNodeByAggregateId = []; + $matchingNodeByAggregateId = null; $filter = FindDescendantNodesFilter::create(); if (isset($arguments[0]) && $arguments[0] !== '') { if ($nodeAggregateId = NodeAggregateId::tryFromString($arguments[0])) {