From 5a8ab499476ee1106829779787cebf5c57a8b836 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:14:18 +0200 Subject: [PATCH] TASK: Introduce `Nodes::prepend` and cleanup code --- .../Classes/Projection/ContentGraph/Nodes.php | 5 ++++ .../Controller/Service/NodesController.php | 30 ++++++++++--------- phpstan-baseline.neon | 10 +++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Nodes.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Nodes.php index 988a35fe361..ef55a5f8afe 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Nodes.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/Nodes.php @@ -124,6 +124,11 @@ public function merge(self $other): self return self::fromArray($nodes); } + public function prepend(Node $node): self + { + return new self([$node, ...$this->nodes]); + } + public function append(Node $node): self { return new self([...$this->nodes, $node]); diff --git a/Neos.Neos/Classes/Controller/Service/NodesController.php b/Neos.Neos/Classes/Controller/Service/NodesController.php index fef2fff8a8e..5faf919d6ae 100644 --- a/Neos.Neos/Classes/Controller/Service/NodesController.php +++ b/Neos.Neos/Classes/Controller/Service/NodesController.php @@ -25,6 +25,7 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\ExpandedNodeTypeCriteria; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria; +use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\SearchTerm\SearchTerm; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\SearchTerm\SearchTermMatcher; use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate; use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes; @@ -113,6 +114,11 @@ public function indexAction( string $contextNode = null, array|string $nodeIdentifiers = [] ): void { + $searchTerm = $searchTerm === '' ? null : SearchTerm::fulltext($searchTerm); + $nodeTypeCriteria = NodeTypeCriteria::create( + NodeTypeNames::fromStringArray($nodeTypes), + NodeTypeNames::createEmpty() + ); $nodeIds = $nodeIds ?: $nodeIdentifiers; $nodeIds = is_array($nodeIds) ? $nodeIds : [$nodeIds]; $contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest()) @@ -143,6 +149,7 @@ public function indexAction( ); } + $nodes = []; if ($nodeIds === [] && (!is_null($nodeAddress) || !is_null($nodePath))) { if (!is_null($nodeAddress)) { $entryNode = $subgraph->findNodeById($nodeAddress->aggregateId); @@ -151,33 +158,28 @@ public function indexAction( $entryNode = $subgraph->findNodeByAbsolutePath($nodePath); } - $nodes = Nodes::createEmpty(); if (!is_null($entryNode)) { - $filter = FindDescendantNodesFilter::create( - nodeTypes: NodeTypeCriteria::create( - NodeTypeNames::fromStringArray($nodeTypes), - NodeTypeNames::createEmpty() - ), - searchTerm: $searchTerm, + $nodes = $subgraph->findDescendantNodes( + $entryNode->aggregateId, + FindDescendantNodesFilter::create( + nodeTypes: $nodeTypeCriteria, + searchTerm: $searchTerm, + ) ); if ( - SearchTermMatcher::matchesNode($entryNode, $filter->searchTerm) - && ExpandedNodeTypeCriteria::create($filter->nodeTypes, $contentRepository->getNodeTypeManager()) + SearchTermMatcher::matchesNode($entryNode, $searchTerm) + && ExpandedNodeTypeCriteria::create($nodeTypeCriteria, $contentRepository->getNodeTypeManager()) ->matches($entryNode->nodeTypeName) ) { // include the starting node if it matches - $nodes = $nodes->append($entryNode); + $nodes = $nodes->prepend($entryNode); } - $nodes = $nodes->merge( - $subgraph->findDescendantNodes($entryNode->aggregateId, $filter) - ); } } else { if (!empty($searchTerm)) { throw new \RuntimeException('Combination of $nodeIdentifiers and $searchTerm not supported'); } - $nodes = []; foreach ($nodeIds as $nodeAggregateId) { $node = $subgraph->findNodeById( NodeAggregateId::fromString($nodeAggregateId) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0dd318d2ae9..663b53980ff 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -165,6 +165,16 @@ parameters: count: 1 path: Neos.Neos/Classes/Controller/Module/User/UserSettingsController.php + - + message: "#^Parameter \\#2 \\$searchTerm of static method Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTermMatcher\\:\\:matchesNode\\(\\) expects Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTerm, Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\SearchTerm\\\\SearchTerm\\|null given\\.$#" + count: 1 + path: Neos.Neos/Classes/Controller/Service/NodesController.php + + - + message: "#^The internal method \"Neos\\\\ContentRepository\\\\Core\\\\Projection\\\\ContentGraph\\\\Filter\\\\NodeType\\\\ExpandedNodeTypeCriteria\\:\\:matches\" is called\\.$#" + count: 1 + path: Neos.Neos/Classes/Controller/Service/NodesController.php + - message: "#^The internal method \"Neos\\\\ContentRepository\\\\Core\\\\DimensionSpace\\\\WeightedDimensionSpacePoint\\:\\:getIdentityHash\" is called\\.$#" count: 3