From d0986b21d940d08428746a229f6a566fca3bcbcf Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 23 Dec 2024 14:18:19 +0100 Subject: [PATCH 1/6] FEATURE: Improve context rewrites in fusion --- config/set/contentrepository-90.php | 4 +- .../Context/content-context.fusion.inc | 39 +++++++++++++++++ .../context-current-rendering-mode.fusion.inc | 42 +++++++++++++++++++ .../Context/context-current-site.fusion.inc | 2 +- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Context/context-current-rendering-mode.fusion.inc diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 662271c..e0fd8e0 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -393,7 +393,7 @@ $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.currentDomain', 'Line %LINE: !! node.context.currentDomain is removed in Neos 9.0.'); // ContentContext::getCurrentSiteNode $methodCallToWarningComments[] = new MethodCallToWarningComment(LegacyContextStub::class, 'getCurrentSiteNode', '!! ContentContext::getCurrentSiteNode() is removed in Neos 9.0. Use Subgraph and traverse up to "Neos.Neos:Site" node.'); - $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.currentSiteNode', 'Line %LINE: !! node.context.currentSiteNode is removed in Neos 9.0.'); + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.currentSiteNode', 'Line %LINE: !! node.context.currentSiteNode is removed in Neos 9.0. Check if you can\'t simply use ${site}.'); // ContentContext::isLive -> renderingMode.isLive $rectorConfig->rule(ContextIsLiveRector::class); $rectorConfig->rule(FusionContextLiveRector::class); @@ -403,6 +403,8 @@ // ContentContext::getCurrentRenderingMode... -> renderingMode... $rectorConfig->rule(ContextGetCurrentRenderingModeRector::class); $rectorConfig->rule(FusionContextCurrentRenderingModeRector::class); + // ContentContext::getProperties(): array + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.properties', 'Line %LINE: !! node.context.properties is removed in Neos 9.0.'); /** * CreateContentContextTrait diff --git a/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc new file mode 100644 index 0000000..704994b --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc @@ -0,0 +1,39 @@ +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + currentSite = ${node.context.currentSite} + currentSiteNode = ${node.context.currentSiteNode} + currentDomain = ${node.context.currentDomain} + + isLive = ${node.context.isLive} + isInBackend = ${node.context.isInBackend} + + preview = ${node.context.currentRenderingMode.preview} + edit = ${node.context.currentRenderingMode.edit} + name = ${node.context.currentRenderingMode.name} + currentRenderingMode = ${node.context.currentRenderingMode} + + properties = ${node.context.properties} + +} +----- +// TODO 9.0 migration: Line 9: !! node.context.currentDomain is removed in Neos 9.0. +// TODO 9.0 migration: Line 8: !! node.context.currentSiteNode is removed in Neos 9.0. Check if you can't simply use ${site}. +// TODO 9.0 migration: Line 19: !! node.context.properties is removed in Neos 9.0. +// TODO 9.0 migration: Line 14: 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.Context:Prototype) < prototype(Neos.Fusion:Component) { + + currentSite = ${Neos.Site.findBySiteNode(site)} + currentSiteNode = ${node.context.currentSiteNode} + currentDomain = ${node.context.currentDomain} + + isLive = ${node.context.isLive} + isInBackend = ${node.context.isInBackend} + + preview = ${renderingMode.isPreview} + edit = ${renderingMode.isEdit} + name = ${renderingMode.name} + currentRenderingMode = ${node.context.currentRenderingMode} + + properties = ${node.context.properties} + +} diff --git a/tests/Sets/ContentRepository90/Fixture/Context/context-current-rendering-mode.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context-current-rendering-mode.fusion.inc new file mode 100644 index 0000000..8dcd68e --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Context/context-current-rendering-mode.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/Sets/ContentRepository90/Fixture/Context/context-current-site.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context-current-site.fusion.inc index 62df678..e016d3e 100644 --- a/tests/Sets/ContentRepository90/Fixture/Context/context-current-site.fusion.inc +++ b/tests/Sets/ContentRepository90/Fixture/Context/context-current-site.fusion.inc @@ -6,7 +6,7 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie } } ----- -// TODO 9.0 migration: Line 6: !! node.context.currentSiteNode is removed in Neos 9.0. +// TODO 9.0 migration: Line 6: !! node.context.currentSiteNode is removed in Neos 9.0. Check if you can't simply use ${site}. prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { renderer = Neos.Fusion:Component { attributes = ${Neos.Site.findBySiteNode(site).siteResourcesPackageKey || Neos.Site.findBySiteNode(site).siteResourcesPackageKey || Neos.Site.findBySiteNode(site).siteResourcesPackageKey} From d17993a00f8869fd039b5c7aa40fd588249bd095 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 23 Dec 2024 14:57:18 +0100 Subject: [PATCH 2/6] FEATURE: Improve context rewrites in fusion --- config/set/contentrepository-90.php | 41 ++++++++++++++-- .../FusionContextGetWorkspaceNameRector.php | 31 ++++++++++++ .../Fixture/some_file.fusion.inc | 32 +++++++++++++ ...usionContextGetWorkspaceNameRectorTest.php | 31 ++++++++++++ .../config/configured_rule.php | 18 +++++++ .../Context/content-context.fusion.inc | 2 +- .../Fixture/Context/context.fusion.inc | 48 +++++++++++++++++++ 7 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/FusionContextGetWorkspaceNameRectorTest.php create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/config/configured_rule.php create mode 100644 tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index e0fd8e0..97c0e03 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -20,6 +20,7 @@ use Neos\Rector\ContentRepository90\Rules\FusionCachingNodeInEntryIdentifierRector; use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector; use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentSiteRector; +use Neos\Rector\ContentRepository90\Rules\FusionContextGetWorkspaceNameRector; use Neos\Rector\ContentRepository90\Rules\FusionContextInBackendRector; use Neos\Rector\ContentRepository90\Rules\FusionContextLiveRector; use Neos\Rector\ContentRepository90\Rules\FusionNodeAggregateIdentifierRector; @@ -366,10 +367,10 @@ $rectorConfig->rule(ContextFactoryToLegacyContextStubRector::class); // Context::getWorkspaceName() // TODO: PHP - // TODO: Fusion + $rectorConfig->rule(FusionContextGetWorkspaceNameRector::class); // Context::getRootNode() $rectorConfig->rule(ContextGetRootNodeRector::class); - // TODO: Fusion + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.rootNode', 'Line %LINE: !! node.context.rootNode is removed in Neos 9.0.'); // Context::getNode() // TODO: PHP // Context::getNodeByIdentifier() @@ -379,9 +380,43 @@ // Context::getNodesOnPath() // TODO: PHP // Context::adoptNode() + // TODO: PHP // Context::getFirstLevelNodeCache() $rectorConfig->rule(ContextGetFirstLevelNodeCacheRector::class); + // getCurrentDateTime(): DateTime|DateTimeInterface + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.currentDateTime', 'Line %LINE: !! node.context.currentDateTime is removed in Neos 9.0.'); + // getDimensions(): array + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.dimensions', 'Line %LINE: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now.'); + // getNodeByIdentifier(identifier: string): NodeInterface|null + // TODO: PHP + // getProperties(): array + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.properties', 'Line %LINE: !! node.context.properties is removed in Neos 9.0.'); + // getTargetDimensions(): array + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.targetDimensions', 'Line %LINE: !! node.context.targetDimensions is removed in Neos 9.0.'); + // getTargetDimensionValues(): array + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.targetDimensionValues', 'Line %LINE: !! node.context.targetDimensionValues is removed in Neos 9.0.'); + // getWorkspace([createWorkspaceIfNecessary: bool = true]): Workspace + // TODO: PHP + // TODO: Fusion? + // isInaccessibleContentShown(): bool + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.isInaccessibleContentShown', 'Line %LINE: !! node.context.isInaccessibleContentShown is removed in Neos 9.0.'); + // isInvisibleContentShown(): bool + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.isInvisibleContentShown', 'Line %LINE: !! node.context.isInvisibleContentShown is removed in Neos 9.0.'); + // isRemovedContentShown(): bool + // TODO: PHP + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.isRemovedContentShown', 'Line %LINE: !! node.context.isRemovedContentShown is removed in Neos 9.0.'); + // validateWorkspace(workspace: Workspace): void + // TODO: PHP + + /** * ContentContext */ @@ -403,8 +438,6 @@ // ContentContext::getCurrentRenderingMode... -> renderingMode... $rectorConfig->rule(ContextGetCurrentRenderingModeRector::class); $rectorConfig->rule(FusionContextCurrentRenderingModeRector::class); - // ContentContext::getProperties(): array - $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.properties', 'Line %LINE: !! node.context.properties is removed in Neos 9.0.'); /** * CreateContentContextTrait diff --git a/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php b/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php new file mode 100644 index 0000000..ce97820 --- /dev/null +++ b/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php @@ -0,0 +1,31 @@ +process(fn(string $eelExpression) => preg_replace( + '/(node|documentNode|site)\.context\.workspaceName/', + '$1.workspaceName', + $eelExpression + )) + ->addCommentsIfRegexMatches( + '/\.context\.workspaceName/', + '// TODO 9.0 migration: Line %LINE: You very likely need to rewrite "VARIABLE.context.workspaceName" to "VARIABLE.workspaceName". 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/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc new file mode 100644 index 0000000..b3cdc58 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc @@ -0,0 +1,32 @@ +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspaceName = ${node.context.workspaceName} + + attributes = ${node.context.workspaceName || site.context.workspaceName || documentNode.context.workspaceName} + + + renderer = afx` + + ` +} +----- +// TODO 9.0 migration: Line 13: You very likely need to rewrite "VARIABLE.context.workspaceName" to "VARIABLE.workspaceName". We did not auto-apply this migration because we cannot be sure whether the variable is a Node. +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspaceName = ${node.workspaceName} + + attributes = ${node.workspaceName || site.workspaceName || documentNode.workspaceName} + + + renderer = afx` + + ` +} diff --git a/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/FusionContextGetWorkspaceNameRectorTest.php b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/FusionContextGetWorkspaceNameRectorTest.php new file mode 100644 index 0000000..3722422 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/FusionContextGetWorkspaceNameRectorTest.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/FusionContextGetWorkspaceNameRector/config/configured_rule.php b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/config/configured_rule.php new file mode 100644 index 0000000..95cfe63 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/config/configured_rule.php @@ -0,0 +1,18 @@ +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(FusionContextGetWorkspaceNameRector::class); +}; diff --git a/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc index 704994b..f61801b 100644 --- a/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc +++ b/tests/Sets/ContentRepository90/Fixture/Context/content-context.fusion.inc @@ -16,9 +16,9 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { } ----- +// TODO 9.0 migration: Line 19: !! node.context.properties is removed in Neos 9.0. // TODO 9.0 migration: Line 9: !! node.context.currentDomain is removed in Neos 9.0. // TODO 9.0 migration: Line 8: !! node.context.currentSiteNode is removed in Neos 9.0. Check if you can't simply use ${site}. -// TODO 9.0 migration: Line 19: !! node.context.properties is removed in Neos 9.0. // TODO 9.0 migration: Line 14: 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.Context:Prototype) < prototype(Neos.Fusion:Component) { diff --git a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc new file mode 100644 index 0000000..f93f0ee --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc @@ -0,0 +1,48 @@ +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspaceName = ${node.context.workspaceName} + rootNode = ${node.context.rootNode} + + currentDateTime = ${node.context.currentDateTime} + dimensions = ${node.context.dimensions} + properties = ${node.context.properties} + + targetDimensions = ${node.context.targetDimensions} + targetDimensionValues = ${node.context.targetDimensionValues} + + workspace = ${node.context.workspace} + + isInaccessibleContentShown = ${node.context.isInaccessibleContentShown} + isInvisibleContentShown = ${node.context.isInvisibleContentShown} + isRemovedContentShown = ${node.context.isRemovedContentShown} + +} +----- +// TODO 9.0 migration: Line 13: !! node.context.rootNode is removed in Neos 9.0. +// TODO 9.0 migration: Line 15: !! node.context.currentDateTime is removed in Neos 9.0. +// TODO 9.0 migration: Line 16: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now. +// TODO 9.0 migration: Line 17: !! node.context.properties is removed in Neos 9.0. +// TODO 9.0 migration: Line 19: !! node.context.targetDimensions is removed in Neos 9.0. +// TODO 9.0 migration: Line 20: !! node.context.targetDimensionValues is removed in Neos 9.0. +// TODO 9.0 migration: Line 24: !! node.context.isInaccessibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 25: !! node.context.isInvisibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 26: !! node.context.isRemovedContentShown is removed in Neos 9.0. +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspaceName = ${node.workspaceName} + rootNode = ${node.context.rootNode} + + currentDateTime = ${node.context.currentDateTime} + dimensions = ${node.context.dimensions} + properties = ${node.context.properties} + + targetDimensions = ${node.context.targetDimensions} + targetDimensionValues = ${node.context.targetDimensionValues} + + workspace = ${node.context.workspace} + + isInaccessibleContentShown = ${node.context.isInaccessibleContentShown} + isInvisibleContentShown = ${node.context.isInvisibleContentShown} + isRemovedContentShown = ${node.context.isRemovedContentShown} + +} From 8411258dc47d23a0c3d0472cf17b48e264aa1563 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 23 Dec 2024 20:44:11 +0100 Subject: [PATCH 3/6] FEATURE: Improve context rewrites in fusion --- .../FusionContextGetWorkspaceNameRector.php | 2 +- .../Fixture/some_file.fusion.inc | 4 +++- .../Fixture/Context/context.fusion.inc | 20 ++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php b/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php index ce97820..c4e9653 100644 --- a/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php +++ b/src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.php @@ -19,7 +19,7 @@ public function refactorFileContent(string $fileContent): string { return EelExpressionTransformer::parse($fileContent) ->process(fn(string $eelExpression) => preg_replace( - '/(node|documentNode|site)\.context\.workspaceName/', + '/(node|documentNode|site)\.context\.(workspaceName|workspace\.name)\b/', '$1.workspaceName', $eelExpression )) diff --git a/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc index b3cdc58..f78762a 100644 --- a/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/Fixture/some_file.fusion.inc @@ -1,6 +1,7 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { workspaceName = ${node.context.workspaceName} + workspaceNameByWorkspace = ${node.context.workspace.name} attributes = ${node.context.workspaceName || site.context.workspaceName || documentNode.context.workspaceName} @@ -14,10 +15,11 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { ` } ----- -// TODO 9.0 migration: Line 13: You very likely need to rewrite "VARIABLE.context.workspaceName" to "VARIABLE.workspaceName". We did not auto-apply this migration because we cannot be sure whether the variable is a Node. +// TODO 9.0 migration: Line 14: You very likely need to rewrite "VARIABLE.context.workspaceName" to "VARIABLE.workspaceName". We did not auto-apply this migration because we cannot be sure whether the variable is a Node. prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { workspaceName = ${node.workspaceName} + workspaceNameByWorkspace = ${node.workspaceName} attributes = ${node.workspaceName || site.workspaceName || documentNode.workspaceName} diff --git a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc index f93f0ee..ba17687 100644 --- a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc +++ b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc @@ -1,6 +1,7 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { workspaceName = ${node.context.workspaceName} + workspaceNameByWorkspace = ${node.context.workspace.name} rootNode = ${node.context.rootNode} currentDateTime = ${node.context.currentDateTime} @@ -18,18 +19,19 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { } ----- -// TODO 9.0 migration: Line 13: !! node.context.rootNode is removed in Neos 9.0. -// TODO 9.0 migration: Line 15: !! node.context.currentDateTime is removed in Neos 9.0. -// TODO 9.0 migration: Line 16: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now. -// TODO 9.0 migration: Line 17: !! node.context.properties is removed in Neos 9.0. -// TODO 9.0 migration: Line 19: !! node.context.targetDimensions is removed in Neos 9.0. -// TODO 9.0 migration: Line 20: !! node.context.targetDimensionValues is removed in Neos 9.0. -// TODO 9.0 migration: Line 24: !! node.context.isInaccessibleContentShown is removed in Neos 9.0. -// TODO 9.0 migration: Line 25: !! node.context.isInvisibleContentShown is removed in Neos 9.0. -// TODO 9.0 migration: Line 26: !! node.context.isRemovedContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 14: !! node.context.rootNode is removed in Neos 9.0. +// TODO 9.0 migration: Line 16: !! node.context.currentDateTime is removed in Neos 9.0. +// TODO 9.0 migration: Line 17: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now. +// TODO 9.0 migration: Line 18: !! node.context.properties is removed in Neos 9.0. +// TODO 9.0 migration: Line 20: !! node.context.targetDimensions is removed in Neos 9.0. +// TODO 9.0 migration: Line 21: !! node.context.targetDimensionValues is removed in Neos 9.0. +// TODO 9.0 migration: Line 25: !! node.context.isInaccessibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 26: !! node.context.isInvisibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 27: !! node.context.isRemovedContentShown is removed in Neos 9.0. prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { workspaceName = ${node.workspaceName} + workspaceNameByWorkspace = ${node.workspaceName} rootNode = ${node.context.rootNode} currentDateTime = ${node.context.currentDateTime} From 48a6253987b883379ca2bab9c8d751e50d5efb26 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 6 Jan 2025 14:21:43 +0100 Subject: [PATCH 4/6] TASK: Extend warning message Co-authored-by: Marc Henry Schultz <85400359+mhsdesign@users.noreply.github.com> --- config/set/contentrepository-90.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 97c0e03..6baee97 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -388,7 +388,7 @@ $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.currentDateTime', 'Line %LINE: !! node.context.currentDateTime is removed in Neos 9.0.'); // getDimensions(): array // TODO: PHP - $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.dimensions', 'Line %LINE: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now.'); + $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.dimensions', 'Line %LINE: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now or use the `Neos.Dimension.*` helper.'); // getNodeByIdentifier(identifier: string): NodeInterface|null // TODO: PHP // getProperties(): array From 034217cb1233eed5c53b138a51e110e01ef2cc31 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 7 Jan 2025 14:08:50 +0100 Subject: [PATCH 5/6] TASK: Extend warning message --- .../Sets/ContentRepository90/Fixture/Context/context.fusion.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc index ba17687..ffd5bf4 100644 --- a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc +++ b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc @@ -21,7 +21,7 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { ----- // TODO 9.0 migration: Line 14: !! node.context.rootNode is removed in Neos 9.0. // TODO 9.0 migration: Line 16: !! node.context.currentDateTime is removed in Neos 9.0. -// TODO 9.0 migration: Line 17: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now. +// TODO 9.0 migration: Line 17: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now or use the `Neos.Dimension.*` helper. // TODO 9.0 migration: Line 18: !! node.context.properties is removed in Neos 9.0. // TODO 9.0 migration: Line 20: !! node.context.targetDimensions is removed in Neos 9.0. // TODO 9.0 migration: Line 21: !! node.context.targetDimensionValues is removed in Neos 9.0. From e8874737ba38a34961dc264e699a426da39c52d0 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 7 Jan 2025 14:46:20 +0100 Subject: [PATCH 6/6] FEATURE: Improve context rewrites in fusion --- config/set/contentrepository-90.php | 3 +- .../Rules/FusionContextGetWorkspaceRector.php | 26 ++++++++++++ .../Fixture/some_file.fusion.inc | 40 +++++++++++++++++++ .../FusionContextGetWorkspaceRectorTest.php | 31 ++++++++++++++ .../config/configured_rule.php | 18 +++++++++ .../Fixture/Context/context.fusion.inc | 22 +++++----- 6 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 src/ContentRepository90/Rules/FusionContextGetWorkspaceRector.php create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/Fixture/some_file.fusion.inc create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/FusionContextGetWorkspaceRectorTest.php create mode 100644 tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/config/configured_rule.php diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 6baee97..0dffe8e 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -21,6 +21,7 @@ use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector; use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentSiteRector; use Neos\Rector\ContentRepository90\Rules\FusionContextGetWorkspaceNameRector; +use Neos\Rector\ContentRepository90\Rules\FusionContextGetWorkspaceRector; use Neos\Rector\ContentRepository90\Rules\FusionContextInBackendRector; use Neos\Rector\ContentRepository90\Rules\FusionContextLiveRector; use Neos\Rector\ContentRepository90\Rules\FusionNodeAggregateIdentifierRector; @@ -402,7 +403,7 @@ $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.targetDimensionValues', 'Line %LINE: !! node.context.targetDimensionValues is removed in Neos 9.0.'); // getWorkspace([createWorkspaceIfNecessary: bool = true]): Workspace // TODO: PHP - // TODO: Fusion? + $rectorConfig->rule(FusionContextGetWorkspaceRector::class); // isInaccessibleContentShown(): bool // TODO: PHP $fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('context.isInaccessibleContentShown', 'Line %LINE: !! node.context.isInaccessibleContentShown is removed in Neos 9.0.'); diff --git a/src/ContentRepository90/Rules/FusionContextGetWorkspaceRector.php b/src/ContentRepository90/Rules/FusionContextGetWorkspaceRector.php new file mode 100644 index 0000000..f91333e --- /dev/null +++ b/src/ContentRepository90/Rules/FusionContextGetWorkspaceRector.php @@ -0,0 +1,26 @@ +addCommentsIfRegexMatches( + '/\.context\.workspace(\.\w)?\b/', + '// TODO 9.0 migration: Line %LINE: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result.' + )->getProcessedContent(); + } +} diff --git a/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/Fixture/some_file.fusion.inc new file mode 100644 index 0000000..95f26f0 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/Fixture/some_file.fusion.inc @@ -0,0 +1,40 @@ +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspace = ${node.context.workspace} + workspaceName = ${node.context.workspaceName} + workspaceNameByWorkspace = ${node.context.workspace.name} + + attributes = ${node.context.workspace || site.context.workspace || documentNode.context.workspace} + + + renderer = afx` + + ` +} +----- +// TODO 9.0 migration: Line 8: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +// TODO 9.0 migration: Line 10: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +// TODO 9.0 migration: Line 12: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +// TODO 9.0 migration: Line 18: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +// TODO 9.0 migration: Line 19: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { + + workspace = ${node.context.workspace} + workspaceName = ${node.context.workspaceName} + workspaceNameByWorkspace = ${node.context.workspace.name} + + attributes = ${node.context.workspace || site.context.workspace || documentNode.context.workspace} + + + renderer = afx` + + ` +} diff --git a/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/FusionContextGetWorkspaceRectorTest.php b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/FusionContextGetWorkspaceRectorTest.php new file mode 100644 index 0000000..93ce5c7 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/FusionContextGetWorkspaceRectorTest.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/FusionContextGetWorkspaceRector/config/configured_rule.php b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/config/configured_rule.php new file mode 100644 index 0000000..908e746 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionContextGetWorkspaceRector/config/configured_rule.php @@ -0,0 +1,18 @@ +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(FusionContextGetWorkspaceRector::class); +}; diff --git a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc index ffd5bf4..6713d31 100644 --- a/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc +++ b/tests/Sets/ContentRepository90/Fixture/Context/context.fusion.inc @@ -12,6 +12,7 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { targetDimensionValues = ${node.context.targetDimensionValues} workspace = ${node.context.workspace} + workspaceSomeProperty = ${node.context.workspace.someProperty} isInaccessibleContentShown = ${node.context.isInaccessibleContentShown} isInvisibleContentShown = ${node.context.isInvisibleContentShown} @@ -19,15 +20,17 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { } ----- -// TODO 9.0 migration: Line 14: !! node.context.rootNode is removed in Neos 9.0. -// TODO 9.0 migration: Line 16: !! node.context.currentDateTime is removed in Neos 9.0. -// TODO 9.0 migration: Line 17: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now or use the `Neos.Dimension.*` helper. -// TODO 9.0 migration: Line 18: !! node.context.properties is removed in Neos 9.0. -// TODO 9.0 migration: Line 20: !! node.context.targetDimensions is removed in Neos 9.0. -// TODO 9.0 migration: Line 21: !! node.context.targetDimensionValues is removed in Neos 9.0. -// TODO 9.0 migration: Line 25: !! node.context.isInaccessibleContentShown is removed in Neos 9.0. -// TODO 9.0 migration: Line 26: !! node.context.isInvisibleContentShown is removed in Neos 9.0. -// TODO 9.0 migration: Line 27: !! node.context.isRemovedContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 16: !! node.context.rootNode is removed in Neos 9.0. +// TODO 9.0 migration: Line 18: !! node.context.currentDateTime is removed in Neos 9.0. +// TODO 9.0 migration: Line 19: !! node.context.dimensions is removed in Neos 9.0. You can get node DimensionSpacePoints via node.dimensionSpacePoints now or use the `Neos.Dimension.*` helper. +// TODO 9.0 migration: Line 20: !! node.context.properties is removed in Neos 9.0. +// TODO 9.0 migration: Line 22: !! node.context.targetDimensions is removed in Neos 9.0. +// TODO 9.0 migration: Line 23: !! node.context.targetDimensionValues is removed in Neos 9.0. +// TODO 9.0 migration: Line 28: !! node.context.isInaccessibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 29: !! node.context.isInvisibleContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 30: !! node.context.isRemovedContentShown is removed in Neos 9.0. +// TODO 9.0 migration: Line 16: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. +// TODO 9.0 migration: Line 17: You very likely need to rewrite "VARIABLE.context.workspace" as the "context" of nodes has been removed without a direct replacement in Neos 9. If you really need the workspace in fusion you need to create a dedicated helper yourself which should ideally do ALL the complex logic in php directly and return the computed result. prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { workspaceName = ${node.workspaceName} @@ -42,6 +45,7 @@ prototype(Neos.Context:Prototype) < prototype(Neos.Fusion:Component) { targetDimensionValues = ${node.context.targetDimensionValues} workspace = ${node.context.workspace} + workspaceSomeProperty = ${node.context.workspace.someProperty} isInaccessibleContentShown = ${node.context.isInaccessibleContentShown} isInvisibleContentShown = ${node.context.isInvisibleContentShown}