From bf8727300334289f66ae521bb031f7621c459194 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 23 Oct 2023 08:19:50 +0200 Subject: [PATCH] BUGFIX: Replace fusion node.parent with proper FlowQuery --- .../Rules/FusionNodeParentRector.php | 8 ++--- .../Fixture/some_file.fusion.inc | 30 +++---------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/ContentRepository90/Rules/FusionNodeParentRector.php b/src/ContentRepository90/Rules/FusionNodeParentRector.php index 8b8bdba..8a66bf5 100644 --- a/src/ContentRepository90/Rules/FusionNodeParentRector.php +++ b/src/ContentRepository90/Rules/FusionNodeParentRector.php @@ -14,7 +14,7 @@ class FusionNodeParentRector implements FusionRectorInterface public function getRuleDefinition(): RuleDefinition { - return CodeSampleLoader::fromFile('Fusion: Rewrite node.parent to Neos.NodeAccess.findParent(node)', __CLASS__); + return CodeSampleLoader::fromFile('Fusion: Rewrite node.parent to q(node).parent().get(0)', __CLASS__); } public function refactorFileContent(string $fileContent): string @@ -22,12 +22,12 @@ public function refactorFileContent(string $fileContent): string return EelExpressionTransformer::parse($fileContent) ->process(fn(string $eelExpression) => preg_replace( '/(node|documentNode)\.parent/', - 'Neos.NodeAccess.findParent($1)', + 'q($1).parent().get(0)', $eelExpression )) ->addCommentsIfRegexMatches( - '/\.parent/', - '// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.parent" to Neos.NodeAccess.findParent(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' + '/\.parent($|[^(])/', + '// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.parent" to "q(VARIABLE).parent().get(0)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' )->getProcessedContent(); } } diff --git a/tests/ContentRepository90/Rules/FusionNodeParentRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionNodeParentRector/Fixture/some_file.fusion.inc index 120f9ed..66965ae 100644 --- a/tests/ContentRepository90/Rules/FusionNodeParentRector/Fixture/some_file.fusion.inc +++ b/tests/ContentRepository90/Rules/FusionNodeParentRector/Fixture/some_file.fusion.inc @@ -7,17 +7,6 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie # attributes = ${node.parent || documentNode.parent} - # - # the `checked` state is calculated outside the renderer to allow` overriding via `attributes` - # - checked = false - checked.@process.checkMultiValue = ${Array.indexOf(field.getCurrentMultivalueStringified(), field.getTargetValueStringified()) > -1} - checked.@process.checkMultiValue.@if.hasValue = ${field.hasCurrentValue()} - checked.@process.checkMultiValue.@if.isMultiple = ${field.isMultiple()} - checked.@process.checkSingleValue = ${field.getCurrentValueStringified() == field.getTargetValueStringified()} - checked.@process.checkSingleValue.@if.hasValue = ${field.hasCurrentValue()} - checked.@process.checkSingleValue.@if.isSingle = ${!field.isMultiple()} - renderer = afx` -1} - checked.@process.checkMultiValue.@if.hasValue = ${field.hasCurrentValue()} - checked.@process.checkMultiValue.@if.isMultiple = ${field.isMultiple()} - checked.@process.checkSingleValue = ${field.getCurrentValueStringified() == field.getTargetValueStringified()} - checked.@process.checkSingleValue.@if.hasValue = ${field.hasCurrentValue()} - checked.@process.checkSingleValue.@if.isSingle = ${!field.isMultiple()} + attributes = ${q(node).parent().get(0) || q(documentNode).parent().get(0)} renderer = afx` ` }