-
-
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.
- Loading branch information
Showing
14 changed files
with
484 additions
and
7 deletions.
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
33 changes: 33 additions & 0 deletions
33
src/ContentRepository90/Rules/FusionNodeAutoCreatedRector.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 FusionNodeAutoCreatedRector implements FusionRectorInterface | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Rewrite node.autoCreated to node.classification.tethered', __CLASS__); | ||
} | ||
|
||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
return EelExpressionTransformer::parse($fileContent) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.autoCreated/', | ||
'$1.classification.tethered', | ||
$eelExpression | ||
)) | ||
->addCommentsIfRegexMatches( | ||
'/\.autoCreated/', | ||
'// TODO 9.0 migration: Line %LINE: !! You very likely need to rewrite "VARIABLE.autoCreated" to "VARIABLE.classification.tethered". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' | ||
)->getProcessedContent(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/ContentRepository90/Rules/FusionNodeContextPathRector.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 FusionNodeContextPathRector implements FusionRectorInterface | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Rewrite node.contextPath to Neos.Node.serializedNodeAddress(node)', __CLASS__); | ||
} | ||
|
||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
return EelExpressionTransformer::parse($fileContent) | ||
->process(fn(string $eelExpression) => preg_replace( | ||
'/(node|documentNode|site)\.contextPath/', | ||
'Neos.Node.serializedNodeAddress($1)', | ||
$eelExpression | ||
)) | ||
->addCommentsIfRegexMatches( | ||
'/\.contextPath/', | ||
'// TODO 9.0 migration: Line %LINE: !! You very likely need to rewrite "VARIABLE.contextPath" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' | ||
)->getProcessedContent(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Generic/Rules/FusionFlowQueryNodePropertyToWarningCommentRector.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Rector\Generic\Rules; | ||
|
||
use Neos\Rector\Core\FusionProcessing\AfxParser\AfxParserException; | ||
use Neos\Rector\Core\FusionProcessing\EelExpressionTransformer; | ||
use Neos\Rector\Core\FusionProcessing\FusionParser\Exception\ParserException; | ||
use Neos\Rector\Core\FusionProcessing\FusionRectorInterface; | ||
use Neos\Rector\Core\FusionProcessing\Helper\RegexCommentTemplatePair; | ||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
use Webmozart\Assert\Assert; | ||
use Neos\Rector\Generic\ValueObject\FusionFlowQueryNodePropertyToWarningComment; | ||
|
||
class FusionFlowQueryNodePropertyToWarningCommentRector implements FusionRectorInterface, ConfigurableRectorInterface | ||
{ | ||
|
||
use AllTraits; | ||
|
||
/** @var FusionFlowQueryNodePropertyToWarningComment[] */ | ||
private array $fusionFlowQueryNodePropertyToWarningComments = []; | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Adds a warning comment when the defined property is used within an FlowQuery "property()".', __CLASS__, [ | ||
new FusionFlowQueryNodePropertyToWarningComment('_autoCreated', 'Line %LINE: !! You very likely need to rewrite "q(VARIABLE).property("_autoCreated")" to "VARIABLE.classification.tethered". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.') | ||
]); | ||
} | ||
|
||
/** | ||
* @throws ParserException | ||
* @throws AfxParserException | ||
*/ | ||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
|
||
$regexWarningMessagePairs = []; | ||
foreach ($this->fusionFlowQueryNodePropertyToWarningComments as $flowQueryNodePropertyToWarningComment) { | ||
$property = $flowQueryNodePropertyToWarningComment->property; | ||
$regexWarningMessagePairs[] = new RegexCommentTemplatePair( | ||
"/\.property\(('|\")$property('|\")\)/", | ||
(string)self::todoCommentAttribute($flowQueryNodePropertyToWarningComment->warningMessage) | ||
); | ||
|
||
} | ||
|
||
return EelExpressionTransformer::parse($fileContent) | ||
->addCommentsIfRegexesMatch($regexWarningMessagePairs) | ||
->getProcessedContent(); | ||
|
||
} | ||
|
||
/** | ||
* @param FusionFlowQueryNodePropertyToWarningComment[] $configuration | ||
*/ | ||
public function configure(array $configuration): void | ||
{ | ||
Assert::allIsAOf($configuration, FusionFlowQueryNodePropertyToWarningComment::class); | ||
$this->fusionFlowQueryNodePropertyToWarningComments = $configuration; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Generic/ValueObject/FusionFlowQueryNodePropertyToWarningComment.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); | ||
|
||
namespace Neos\Rector\Generic\ValueObject; | ||
|
||
class FusionFlowQueryNodePropertyToWarningComment | ||
{ | ||
public function __construct( | ||
public readonly string $property, | ||
public readonly string $warningMessage, | ||
) | ||
{ | ||
} | ||
|
||
|
||
} |
64 changes: 64 additions & 0 deletions
64
tests/ContentRepository90/Rules/FusionNodeAutoCreatedRector/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,64 @@ | ||
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { | ||
|
||
renderer = Neos.Fusion:Component { | ||
|
||
# | ||
# pass down props | ||
# | ||
attributes = ${node.autoCreated || documentNode.autoCreated} | ||
|
||
# | ||
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes` | ||
# | ||
checked = false | ||
checked.@process.checkMultiValue = ${Array.indexOf(field.getCurrentMultivalueStringified(), field.getTargetValueStringified()) > -1} | ||
checked.@process.checkMultiValue.@if.hasValue = ${field.hasCurrentValue()} | ||
checked.@process.checkMultiValue.@if.isMultiple = ${field.isMultiple()} | ||
checked.@process.checkSingleValue = ${field.getCurrentValueStringified() == field.getTargetValueStringified()} | ||
checked.@process.checkSingleValue.@if.hasValue = ${field.hasCurrentValue()} | ||
checked.@process.checkSingleValue.@if.isSingle = ${!field.isMultiple()} | ||
|
||
renderer = afx` | ||
<input | ||
type="checkbox" | ||
name={node.autoCreated} | ||
value={someOtherVariable.autoCreated} | ||
checked={props.checked} | ||
{...node.autoCreated} | ||
/> | ||
` | ||
} | ||
} | ||
----- | ||
// TODO 9.0 migration: Line 26: !! You very likely need to rewrite "VARIABLE.autoCreated" to "VARIABLE.classification.tethered". 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 { | ||
|
||
# | ||
# pass down props | ||
# | ||
attributes = ${node.classification.tethered || documentNode.classification.tethered} | ||
|
||
# | ||
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes` | ||
# | ||
checked = false | ||
checked.@process.checkMultiValue = ${Array.indexOf(field.getCurrentMultivalueStringified(), field.getTargetValueStringified()) > -1} | ||
checked.@process.checkMultiValue.@if.hasValue = ${field.hasCurrentValue()} | ||
checked.@process.checkMultiValue.@if.isMultiple = ${field.isMultiple()} | ||
checked.@process.checkSingleValue = ${field.getCurrentValueStringified() == field.getTargetValueStringified()} | ||
checked.@process.checkSingleValue.@if.hasValue = ${field.hasCurrentValue()} | ||
checked.@process.checkSingleValue.@if.isSingle = ${!field.isMultiple()} | ||
|
||
renderer = afx` | ||
<input | ||
type="checkbox" | ||
name={node.classification.tethered} | ||
value={someOtherVariable.autoCreated} | ||
checked={props.checked} | ||
{...node.classification.tethered} | ||
/> | ||
` | ||
} | ||
} |
Oops, something went wrong.