-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
FEATURE: Improve context rewrites in fusion #122
Open
dlubitz
wants to merge
4
commits into
main
Choose a base branch
from
feature/context-fusion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/ContentRepository90/Rules/FusionContextGetWorkspaceNameRector.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 | ||
|
||
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 FusionContextGetWorkspaceNameRector implements FusionRectorInterface | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Rewrite "node.context.workspaceName" to "node.workspaceName"', __CLASS__); | ||
} | ||
|
||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
return EelExpressionTransformer::parse($fileContent) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.context\.(workspaceName|workspace\.name)\b/', | ||
'$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(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ontentRepository90/Rules/FusionContextGetWorkspaceNameRector/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,34 @@ | ||
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} | ||
|
||
|
||
renderer = afx` | ||
<Neos.Context:Component | ||
type="checkbox" | ||
name={node.context.workspaceName} | ||
value={someOtherVariable.context.workspaceName} | ||
/> | ||
` | ||
} | ||
----- | ||
// 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} | ||
|
||
|
||
renderer = afx` | ||
<Neos.Context:Component | ||
type="checkbox" | ||
name={node.workspaceName} | ||
value={someOtherVariable.context.workspaceName} | ||
/> | ||
` | ||
} |
31 changes: 31 additions & 0 deletions
31
...y90/Rules/FusionContextGetWorkspaceNameRector/FusionContextGetWorkspaceNameRectorTest.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\FusionContextInBackendRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class FusionContextGetWorkspaceNameRectorTest 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'; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../ContentRepository90/Rules/FusionContextGetWorkspaceNameRector/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,18 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
use Neos\Rector\ContentRepository90\Rules\FusionContextGetWorkspaceNameRector; | ||
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(FusionContextGetWorkspaceNameRector::class); | ||
}; |
39 changes: 39 additions & 0 deletions
39
tests/Sets/ContentRepository90/Fixture/Context/content-context.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,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 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 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} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
tests/Sets/ContentRepository90/Fixture/Context/context-current-rendering-mode.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,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` | ||
<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 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` | ||
<input | ||
type="checkbox" | ||
name={renderingMode.name} | ||
value={renderingMode.title} | ||
checked={renderingMode.isEdit} | ||
{...renderingMode.options} | ||
/> | ||
` | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
tests/Sets/ContentRepository90/Fixture/Context/context.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,50 @@ | ||
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} | ||
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 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} | ||
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} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed here id say write a comment to create a custom eel helper to replace
context.workspace.*
#44 (comment)