From 5f288c6f85ada5c94af6ee2bb2fe97af6174bacc Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Fri, 10 Nov 2023 17:31:40 +0100 Subject: [PATCH] TASK: Add special handling of absolute node pathes since fizzle does not like the new syntax (yet) --- .../FlowQueryOperations/FindOperation.php | 25 ++++++++++++------- .../Features/Fusion/FlowQuery.feature | 10 ++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/FindOperation.php b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/FindOperation.php index b1efe8d2071..c2543d47b7d 100644 --- a/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/FindOperation.php +++ b/Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/FindOperation.php @@ -42,7 +42,7 @@ * * Example (absolute path): * - * q(node).find('/sites/my-site/home') + * q(node).find('//my-site/home') * * Example (identifier): * @@ -118,17 +118,24 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): void return; } - /** @var Node[] $result */ - $result = []; $selectorAndFilter = $arguments[0]; - $parsedFilter = FizzleParser::parseFilterGroup($selectorAndFilter); - - /** @todo fetch them $elsewhere (fusion runtime?) */ $firstContextNode = reset($contextNodes); assert($firstContextNode instanceof Node); - $contentRepository = $this->contentRepositoryRegistry->get($firstContextNode->subgraphIdentity->contentRepositoryId); + $entryPoints = $this->getEntryPoints($contextNodes); + + // handle absolute node pathes and return early as fizzle cannot parse this syntax + if (preg_match('/^\\/<[A-Za-z0-9\\.]+\\:[A-Za-z0-9\\.]+>(\\/[a-z0-9\\-]+)*$/', $selectorAndFilter)) { + $nodePath = AbsoluteNodePath::tryFromString($selectorAndFilter); + $nodes = $this->addNodesByPath($nodePath, $entryPoints, []); + $flowQuery->setContext($nodes); + return; + } + + /** @var Node[] $result */ + $result = []; + $parsedFilter = FizzleParser::parseFilterGroup($selectorAndFilter); $entryPoints = $this->getEntryPoints($contextNodes); foreach ($parsedFilter['Filters'] as $filter) { $filterResults = []; @@ -146,7 +153,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments): void if (isset($filter['AttributeFilters']) && $filter['AttributeFilters'][0]['Operator'] === 'instanceof') { $nodeTypeName = NodeTypeName::fromString($filter['AttributeFilters'][0]['Operand']); - $filterResults = $this->addNodesByType($nodeTypeName, $entryPoints, $filterResults, $contentRepository); + $filterResults = $this->addNodesByType($nodeTypeName, $entryPoints, $filterResults); unset($filter['AttributeFilters'][0]); $generatedNodes = true; } @@ -257,7 +264,7 @@ protected function addNodesByPath(NodePath|AbsoluteNodePath $nodePath, array $en * @param array $result * @return array */ - protected function addNodesByType(NodeTypeName $nodeTypeName, array $entryPoints, array $result, ContentRepository $contentRepository): array + protected function addNodesByType(NodeTypeName $nodeTypeName, array $entryPoints, array $result): array { $nodeTypeFilter = NodeTypeCriteria::create(NodeTypeNames::with($nodeTypeName), NodeTypeNames::createEmpty()); foreach ($entryPoints as $entryPoint) { diff --git a/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature b/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature index 469f65016e8..9289758f8bd 100644 --- a/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature +++ b/Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature @@ -137,6 +137,7 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods. test = Neos.Fusion:DataStructure { noFilter = ${q(node).children().get()} withFilter = ${q(node).children('[instanceof Neos.Neos:Test.DocumentType2]').get()} + withName = ${q(node).children('a1a4').get()} @process.render = Neos.Neos:Test.RenderNodesDataStructure } """ @@ -144,6 +145,7 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods. """ noFilter: a1a1,a1a2,a1a3,a1a4,a1a5,a1a6,a1a7 withFilter: a1a2,a1a3,a1a4,a1a5,a1a6 + withName: a1a4 """ Scenario: Has @@ -357,12 +359,20 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods. # Result in Neos 8.3: "combinedFilter: a1b1a" # Result in Neos 9.0: "combinedFilter: a1a,a1a2,a1b2,a1a3,a1a4,a1a5,a1a6,a1b1a" # combinedFilter = ${q(node).find('[instanceof Neos.Neos:Test.DocumentType2][uriPathSegment*="b1"]').get()} + identifier = ${q(node).find('#a1b1a').get()} + name = ${q(node).find('a1b').get()} + relativePath = ${q(node).find('a1b/a1b1').get()} + absolutePath = ${q(node).find('//a/a1/a1b').get()} @process.render = Neos.Neos:Test.RenderNodesDataStructure } """ Then I expect the following Fusion rendering result: """ typeFilter: a1a,a1a2,a1b2,a1a3,a1a4,a1a5,a1a6,a1b1a + identifier: a1b1a + name: a1b + relativePath: a1b1 + absolutePath: a1b """ Scenario: Unique