Skip to content

Commit

Permalink
Merge pull request #63 from neos/TASK-Replace-node-identifier
Browse files Browse the repository at this point in the history
Change rewrite of node.identifier and q(node).property('identifier') to new q(node).id()
  • Loading branch information
kitsunet authored Jun 2, 2024
2 parents e105c8f + cd4981e commit 1d31ad3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
// getIdentifier
$rectorConfig->rule(NodeGetIdentifierRector::class);
$rectorConfig->rule(FusionNodeIdentifierRector::class);
$fusionFlowQueryPropertyToComments[] = new FusionFlowQueryNodePropertyToWarningComment('_identifier', 'Line %LINE: !! You very likely need to rewrite "q(VARIABLE).property("_identifier")" to "VARIABLE.nodeAggregateId.value". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.');
$fusionFlowQueryPropertyToComments[] = new FusionFlowQueryNodePropertyToWarningComment('_identifier', 'Line %LINE: !! You very likely need to rewrite "q(VARIABLE).property("_identifier")" to "q(VARIABLE).id()". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.');
// setIndex -> internal
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setIndex', '!! Node::setIndex() was always internal. To reorder nodes, use the "MoveNodeAggregate" command');
// getIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class FusionNodeAggregateIdentifierRector implements FusionRectorInterface

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('Fusion: Rewrite node.nodeAggregateIdentifier to node.nodeAggregateId.value', __CLASS__);
return CodeSampleLoader::fromFile('Fusion: Rewrite node.nodeAggregateIdentifier to q(node).id()', __CLASS__);
}

public function refactorFileContent(string $fileContent): string
{
return EelExpressionTransformer::parse($fileContent)
->process(fn(string $eelExpression) => preg_replace(
'/(node|documentNode|site)\.nodeAggregateIdentifier/',
'$1.nodeAggregateId.value',
'q($1).id()',
$eelExpression
))
->addCommentsIfRegexMatches(
Expand Down
15 changes: 6 additions & 9 deletions src/ContentRepository90/Rules/FusionNodeIdentifierRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ class FusionNodeIdentifierRector implements FusionRectorInterface

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('Fusion: Rewrite node.identifier to node.nodeAggregateId.value', __CLASS__);
return CodeSampleLoader::fromFile('Fusion: Rewrite "node.identifier" and "q(node).property(\'_identifier\')" to "q(node).id()"', __CLASS__);
}

public function refactorFileContent(string $fileContent): string
{
return EelExpressionTransformer::parse($fileContent)
->process(fn(string $eelExpression) => preg_replace(
'/(node|documentNode|site)\.identifier/',
'$1.nodeAggregateId.value',
'q($1).id()',
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.identifier/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.identifier" to VARIABLE.nodeAggregateId.value. We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.identifier" to "q(VARIABLE).id()". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->process(fn(string $eelExpression) => preg_replace(
'/(node|documentNode|site)\.property\\(\'_identifier\'\\)/',
'$1.nodeAggregateId.value',
'/\.property\\((\'|")_identifier(\'|")\\)/',
'.id()',
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.property\\(\'_identifier\'\\)/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.identifier" to VARIABLE.nodeAggregateId.value. 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 @@ -24,12 +24,12 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
#
# pass down props
#
attributes = ${node.nodeAggregateId.value || documentNode.nodeAggregateId.value}
attributes = ${q(node).id() || q(documentNode).id()}
renderer = afx`
<input
name={node.nodeAggregateId.value}
name={q(node).id()}
value={someOtherVariable.nodeAggregateIdentifier}
{...node.nodeAggregateId.value}
{...q(node).id()}
/>
`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {

#
# pass down props
#
attributes = ${q(node).property("_identifier") || q(documentNode).property("_identifier")}
renderer = afx`
<input
name={q(node).property('_identifier')}
value={q(someOtherVariable).property("_identifier")}
{...q(node).property("_identifier")}
/>
`
}
}
-----
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {

#
# pass down props
#
attributes = ${q(node).id() || q(documentNode).id()}
renderer = afx`
<input
name={q(node).id()}
value={q(someOtherVariable).id()}
{...q(node).id()}
/>
`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
}
}
-----
// TODO 9.0 migration: Line 13: You may need to rewrite "VARIABLE.identifier" to VARIABLE.nodeAggregateId.value. We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 13: You may need to rewrite "VARIABLE.identifier" to "q(VARIABLE).id()". 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 = ${node.nodeAggregateId.value || documentNode.nodeAggregateId.value}
attributes = ${q(node).id() || q(documentNode).id()}
renderer = afx`
<input
name={node.nodeAggregateId.value}
name={q(node).id()}
value={someOtherVariable.identifier}
{...node.nodeAggregateId.value}
{...q(node).id()}
/>
`
}
Expand Down

0 comments on commit 1d31ad3

Please sign in to comment.