Skip to content

Commit

Permalink
TASK: Add special handling of absolute node pathes since fizzle does …
Browse files Browse the repository at this point in the history
…not like the new syntax (yet)
  • Loading branch information
mficzel committed Nov 10, 2023
1 parent 67f343e commit 5f288c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* Example (absolute path):
*
* q(node).find('/sites/my-site/home')
* q(node).find('/<Neos.Neos:Sites>/my-site/home')
*
* Example (identifier):
*
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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;
}
Expand Down Expand Up @@ -257,7 +264,7 @@ protected function addNodesByPath(NodePath|AbsoluteNodePath $nodePath, array $en
* @param array<int,Node> $result
* @return array<int,Node>
*/
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) {
Expand Down
10 changes: 10 additions & 0 deletions Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ 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
}
"""
Then I expect the following Fusion rendering result:
"""
noFilter: a1a1,a1a2,a1a3,a1a4,a1a5,a1a6,a1a7
withFilter: a1a2,a1a3,a1a4,a1a5,a1a6
withName: a1a4
"""

Scenario: Has
Expand Down Expand Up @@ -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('/<Neos.Neos:Sites>/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
Expand Down

0 comments on commit 5f288c6

Please sign in to comment.