-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Migrate fusion
context.currentRenderingMode
statements
Statements accessing `context.currentRenderingMode.edit|preview|name|title|fusionPath|options` on `node|site|documentNode` are migrated. Other uses of `context.currentRenderingMode` are marked with a comment. Resolves: #23
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use Neos\Rector\Core\FusionProcessing\EelExpressionTransformer; | ||
use Neos\Rector\Core\FusionProcessing\FusionRectorInterface; | ||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
class FusionContextCurrentRenderingModeRector implements FusionRectorInterface | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Rewrite node.context.currentRenderingMode... to renderingMode...', __CLASS__); | ||
} | ||
|
||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
return EelExpressionTransformer::parse($fileContent) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.name', | ||
'renderingMode.name', | ||
$eelExpression | ||
)) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.edit', | ||
'renderingMode.isEdit', | ||
$eelExpression | ||
)) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.preview', | ||
'renderingMode.isPreview', | ||
$eelExpression | ||
)) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.fusionPath', | ||
'renderingMode.fusionPath', | ||
$eelExpression | ||
)) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.options', | ||
'renderingMode.options', | ||
$eelExpression | ||
)) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.currentRenderingMode\.title', | ||
'renderingMode.title', | ||
$eelExpression | ||
)) | ||
->addCommentsIfRegexMatches( | ||
'/\.context\.currentRenderingMode/', | ||
'// TODO 9.0 migration: Line %LINE: You very likely need to rewrite "VARIABLE.context.currentRenderingMode..." to "renderingMode...". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' | ||
)->getProcessedContent(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ntRepository90/Rules/FusionContextCurrentRenderingModeRector/Fixture/some_file.fusion.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { | ||
|
||
renderer = Neos.Fusion:Component { | ||
|
||
# | ||
# pass down props | ||
# | ||
nodeAttributes = ${node.context.currentRenderingMode.edit || node.currentRenderingMode.preview || node.context.currentRenderingMode.title || node.context.currentRenderingMode.name || node.context.currentRenderingMode.fusionPath || node.context.currentRenderingMode.options['foo']} | ||
siteAttributes = ${site.context.currentRenderingMode.edit || site.currentRenderingMode.preview || site.context.currentRenderingMode.title || site.context.currentRenderingMode.name || site.context.currentRenderingMode.fusionPath || site.context.currentRenderingMode.options['foo']} | ||
documentNodeAttributes = ${documentNode.context.currentRenderingMode.edit || documentNode.currentRenderingMode.preview || documentNode.context.currentRenderingMode.title || documentNode.context.currentRenderingMode.name || documentNode.context.currentRenderingMode.fusionPath || documentNode.context.currentRenderingMode.options['foo']} | ||
other = ${other.context.currentRenderingMode.edit || other.currentRenderingMode.preview || other.context.currentRenderingMode.title || other.context.currentRenderingMode.name || other.context.currentRenderingMode.fusionPath || other.context.currentRenderingMode.options['foo']} | ||
|
||
renderer = afx` | ||
<input | ||
type="checkbox" | ||
name={node.context.currentRenderingMode.name} | ||
value={node.context.currentRenderingMode.title} | ||
checked={node.context.currentRenderingMode.edit} | ||
{...node.context.currentRenderingMode.options} | ||
/> | ||
` | ||
} | ||
} | ||
----- | ||
// TODO 9.0 migration: Line 26: You very likely need to rewrite "VARIABLE.context.currentRenderingMode..." to "renderingMode...". 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 { | ||
|
||
nodeAttributes = ${renderingMode.isEdit || renderingMode.isPreview || renderingMode.title || renderingMode.name || renderingMode.fusionPath || renderingMode.options['foo']} | ||
siteAttributes = ${renderingMode.isEdit || renderingMode.isPreview || renderingMode.title || renderingMode.name || renderingMode.fusionPath || renderingMode.options['foo']} | ||
documentNodeAttributes = ${renderingMode.isEdit || renderingMode.isPreview || renderingMode.title || renderingMode.name || renderingMode.fusionPath || renderingMode.options['foo']} | ||
other = ${other.context.currentRenderingMode.edit || other.currentRenderingMode.preview || other.context.currentRenderingMode.title || other.context.currentRenderingMode.name || other.context.currentRenderingMode.fusionPath || other.context.currentRenderingMode.options['foo']} | ||
|
||
renderer = afx` | ||
<input | ||
type="checkbox" | ||
name={renderingMode.name} | ||
value={renderingMode.title} | ||
checked={renderingMode.isEdit} | ||
{...renderingMode.options} | ||
/> | ||
` | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/FusionContextCurrentRenderingModeRector/FusionContextCurrentRenderingModeRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Rector\Tests\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class FusionContextCurrentRenderingModeRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $fileInfo): void | ||
{ | ||
$this->doTestFile($fileInfo); | ||
} | ||
|
||
/** | ||
* @return \Iterator<string> | ||
*/ | ||
public function provideData(): \Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.fusion.inc'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...tentRepository90/Rules/FusionContextCurrentRenderingModeRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig) : void { | ||
$services = $rectorConfig->services(); | ||
$services->defaults() | ||
->public() | ||
->autowire() | ||
->autoconfigure(); | ||
$services->set(\Neos\Rector\Core\FusionProcessing\FusionFileProcessor::class); | ||
$rectorConfig->disableParallel(); // does not work for fusion files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688 | ||
|
||
$rectorConfig->rule(FusionContextCurrentRenderingModeRector::class); | ||
}; |