diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 7d73fad..7f8833b 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -7,6 +7,7 @@ use Neos\Rector\ContentRepository90\Rules\ContextGetFirstLevelNodeCacheRector; use Neos\Rector\ContentRepository90\Rules\ContextGetRootNodeRector; use Neos\Rector\ContentRepository90\Rules\FusionCachingNodeInEntryIdentifierRector; +use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector; use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentSiteRector; use Neos\Rector\ContentRepository90\Rules\FusionContextInBackendRector; use Neos\Rector\ContentRepository90\Rules\FusionContextLiveRector; @@ -281,15 +282,16 @@ // ContentContext::getCurrentSiteNode // TODO: PHP // TODO: Fusion - // ContentContext::isLive -> Neos.Node.isLive(...) + // ContentContext::isLive -> renderingMode.isLive // TODO: PHP $rectorConfig->rule(FusionContextLiveRector::class); - // ContentContext::isInBackend -> Neos.Node.inBackend(...) + // ContentContext::isInBackend -> renderingMode.inBackend // TODO: PHP $rectorConfig->rule(FusionContextInBackendRector::class); - // ContentContext::getCurrentRenderingMode + // ContentContext::getCurrentRenderingMode... -> renderingMode... // TODO: PHP - // TODO: Fusion + $rectorConfig->rule(FusionContextCurrentRenderingModeRector::class); + /** * ContentDimensionCombinator diff --git a/src/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector.php b/src/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector.php new file mode 100644 index 0000000..7c7f545 --- /dev/null +++ b/src/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector.php @@ -0,0 +1,41 @@ +process(fn(string $eelExpression) => preg_replace( + '/(node|documentNode|site)\.context\.currentRenderingMode\.(name|title|fusionPath|options)/', + 'renderingMode.$2', + $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 + )) + ->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(); + } +} diff --git a/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/Fixture/some_file.fusion.inc new file mode 100644 index 0000000..8dcd68e --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/Fixture/some_file.fusion.inc @@ -0,0 +1,42 @@ +prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { + + renderer = Neos.Fusion:Component { + + nodeAttributes = ${node.context.currentRenderingMode.edit || node.context.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.context.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.context.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.context.currentRenderingMode.preview || other.context.currentRenderingMode.title || other.context.currentRenderingMode.name || other.context.currentRenderingMode.fusionPath || other.context.currentRenderingMode.options['foo']} + + renderer = afx` + + ` + } +} +----- +// TODO 9.0 migration: Line 9: 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.context.currentRenderingMode.preview || other.context.currentRenderingMode.title || other.context.currentRenderingMode.name || other.context.currentRenderingMode.fusionPath || other.context.currentRenderingMode.options['foo']} + + renderer = afx` + + ` + } +} diff --git a/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/FusionContextCurrentRenderingModeRectorTest.php b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/FusionContextCurrentRenderingModeRectorTest.php new file mode 100644 index 0000000..8fc413a --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/FusionContextCurrentRenderingModeRectorTest.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.fusion.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/config/configured_rule.php b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/config/configured_rule.php new file mode 100644 index 0000000..c24ab5e --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextCurrentRenderingModeRector/config/configured_rule.php @@ -0,0 +1,17 @@ +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); +};