Skip to content

Commit

Permalink
Merge pull request #80 from neos/bugfix/78-tweak-primary-content-repl…
Browse files Browse the repository at this point in the history
…acement

TASK: Replace usages of `Neos.Neos:PrimaryContent`
  • Loading branch information
bwaidelich authored Sep 26, 2024
2 parents 233d16c + 3f62b19 commit caee8e5
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 6 deletions.
5 changes: 4 additions & 1 deletion config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@
* Neos.Fusion:Attributes
*/
$rectorConfig->ruleWithConfiguration(FusionPrototypeNameAddCommentRector::class, [
new FusionPrototypeNameAddComment('Neos.Neos:PrimaryContent', 'TODO 9.0 migration: You need to refactor "Neos.Neos:PrimaryContent" to use "Neos.Neos:ContentCollection" instead.'),
new FusionPrototypeNameAddComment('Neos.Fusion:Attributes', 'TODO 9.0 migration: Neos.Fusion:Attributes has been removed without a replacement. You need to replace it by the property attributes in Neos.Fusion:Tag')
]);
$rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [
new FusionPrototypeNameReplacement('Neos.Neos:PrimaryContent', 'Neos.Neos:ContentCollection', '"Neos.Neos:PrimaryContent" has been removed without a complete replacement. We replaced all usages with "Neos.Neos:ContentCollection" but not the prototype definition. Please check the replacements and if you have overridden the "Neos.Neos:PrimaryContent" prototype and rewrite it for your needs.', true),
]);


$rectorConfig->rule(ContentRepositoryUtilityRenderValidNodeNameRector::class);

Expand Down
8 changes: 6 additions & 2 deletions src/Generic/Rules/FusionReplacePrototypeNameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ public function refactorFileContent(string $fileContent): string
$comments = [];
foreach ($this->fusionPrototypeNameReplacements as $fusionPrototypeNameReplacement) {
$replacementCount = 0;
$pattern = '/(^|[=\s\(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s\{\)\/>]|$)/';
if ($fusionPrototypeNameReplacement->skipPrototypeDefinitions) {
$pattern = '/(^|[=\s<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s{\/>]|$)/';
} else {
$pattern = '/(^|[=\s(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s{)\/>]|$)/';
}
$replacement = '$1'.$fusionPrototypeNameReplacement->newName.'$3';
$fileContent = preg_replace($pattern, $replacement, $fileContent, count: $replacementCount);

if($replacementCount > 0 && $fusionPrototypeNameReplacement->comment !== null) {
$comments[] = '// TODO 9.0 migration:' . $fusionPrototypeNameReplacement->comment;
$comments[] = '// TODO 9.0 migration: ' . $fusionPrototypeNameReplacement->comment;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Generic/ValueObject/FusionPrototypeNameReplacement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class FusionPrototypeNameReplacement
public function __construct(
public readonly string $oldName,
public readonly string $newName,
public readonly ?string $comment = null
public readonly ?string $comment = null,
public readonly bool $skipPrototypeDefinitions = false,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
prototype(Neos.Neos:Foo) < prototype(Neos.Neos:Bar) {

raw = Neos.Neos:Foo
renderer = afx`
<Neos.Neos:Bar />
`
}
-----
// TODO 9.0 migration: Neos.Neos:FooReplaced: This comment should be added on top of the file.
// TODO 9.0 migration: Neos.Neos:BarReplaced: This comment should be added on top of the file.
prototype(Neos.Neos:Foo) < prototype(Neos.Neos:Bar) {

raw = Neos.Neos:FooReplaced
renderer = afx`
<Neos.Neos:BarReplaced />
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ prototype(Neos.Neos:SomethingOld) < prototype(Neos.Neos:Raw) {
}
}
-----
// TODO 9.0 migration:Neos.Neos:Raw: This comment should be added on top of the file.
// TODO 9.0 migration:Neos.Neos:SomethingOlder: This comment should be added on top of the file.
// TODO 9.0 migration: Neos.Neos:Raw: This comment should be added on top of the file.
// TODO 9.0 migration: Neos.Neos:SomethingOlder: This comment should be added on top of the file.
prototype(Neos.Neos:SomethingNew) < prototype(Neos.Neos:NewRaw) {

raw = Neos.Neos:NewRaw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
new FusionPrototypeNameReplacement('Neos.Neos:NotExisting', 'Neos.Neos:NewNotExisting', 'Neos.Neos:NotExisting: This comment should NOT be added on top of the file.'),
new FusionPrototypeNameReplacement('Neos.Neos:SomethingOld', 'Neos.Neos:SomethingNew'),
new FusionPrototypeNameReplacement('Neos.Neos:SomethingOlder', 'Neos.Neos:SomethingNewer', 'Neos.Neos:SomethingOlder: This comment should be added on top of the file.'),
new FusionPrototypeNameReplacement('Neos.Neos:Foo', 'Neos.Neos:FooReplaced', 'Neos.Neos:FooReplaced: This comment should be added on top of the file.', true),
new FusionPrototypeNameReplacement('Neos.Neos:Bar', 'Neos.Neos:BarReplaced', 'Neos.Neos:BarReplaced: This comment should be added on top of the file.', true),
]);
};
31 changes: 31 additions & 0 deletions tests/Sets/ContentRepository90/ContentRepository90Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Neos\Rector\Tests\Sets\ContentRepository90;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class ContentRepository90Test 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/set/contentrepository-90.php';
}
}
22 changes: 22 additions & 0 deletions tests/Sets/ContentRepository90/Fixture/primary-content.fusion.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
prototype(Neos.Neos:PrimaryContent) {
myArticle {
condition = ${q(node).is('[instanceof My.Site:Article]')}
renderer = My.Site:ArticleRenderer
}
}

content = Neos.Neos:PrimaryContent {
nodePath = 'main'
}
-----
// TODO 9.0 migration: "Neos.Neos:PrimaryContent" has been removed without a complete replacement. We replaced all usages with "Neos.Neos:ContentCollection" but not the prototype definition. Please check the replacements and if you have overridden the "Neos.Neos:PrimaryContent" prototype and rewrite it for your needs.
prototype(Neos.Neos:PrimaryContent) {
myArticle {
condition = ${q(node).is('[instanceof My.Site:Article]')}
renderer = My.Site:ArticleRenderer
}
}

content = Neos.Neos:ContentCollection {
nodePath = 'main'
}

0 comments on commit caee8e5

Please sign in to comment.