Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Replace fusion node.parent with proper FlowQuery #30

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ContentRepository90/Rules/FusionNodeParentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ 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
{
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<input
type="checkbox"
Expand All @@ -30,34 +19,23 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
}
}
-----
// TODO 9.0 migration: Line 26: 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.
// TODO 9.0 migration: Line 15: 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.
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {

#
# pass down props
#
attributes = ${Neos.NodeAccess.findParent(node) || Neos.NodeAccess.findParent(documentNode)}

#
# 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()}
attributes = ${q(node).parent().get(0) || q(documentNode).parent().get(0)}

renderer = afx`
<input
type="checkbox"
name={Neos.NodeAccess.findParent(node)}
name={q(node).parent().get(0)}
value={someOtherVariable.parent}
checked={props.checked}
{...Neos.NodeAccess.findParent(node)}
{...q(node).parent().get(0)}
/>
`
}
Expand Down
Loading