-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add RemoveElementTceFormsRector (#3460)
- Loading branch information
1 parent
ffb81ad
commit 72b1f9c
Showing
7 changed files
with
271 additions
and
1 deletion.
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
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
104 changes: 104 additions & 0 deletions
104
src/Rector/v12/v0/flexform/RemoveElementTceFormsRector.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,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v12\v0\flexform; | ||
|
||
use DOMDocument; | ||
use DOMElement; | ||
use DOMNodeList; | ||
use DOMXPath; | ||
use Ssch\TYPO3Rector\Contract\FileProcessor\FlexForms\Rector\FlexFormRectorInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-97126-TCEformsRemovedInFlexForm.html | ||
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\flexform\RemoveElementTceFormsRector\RemoveElementTceFormsRectorTest | ||
*/ | ||
final class RemoveElementTceFormsRector implements FlexFormRectorInterface | ||
{ | ||
public function transform(DOMDocument $domDocument): bool | ||
{ | ||
$hasChanged = false; | ||
|
||
// Create a DOMXPath object to query the document | ||
$xpath = new DOMXPath($domDocument); | ||
|
||
// Find all elements with a <TCEforms> parent and move their children to the parent level | ||
$tceformsElements = $xpath->query('//TCEforms'); | ||
|
||
if (! $tceformsElements instanceof DOMNodeList) { | ||
return false; | ||
} | ||
|
||
foreach ($tceformsElements as $tceformsElement) { | ||
$parent = $tceformsElement->parentNode; | ||
|
||
if (! $parent instanceof DOMElement) { | ||
return false; | ||
} | ||
|
||
// Move the children of <TCEforms> to the parent | ||
foreach ($tceformsElement->childNodes as $childNode) { | ||
if (! $childNode instanceof DOMElement) { | ||
continue; | ||
} | ||
|
||
$parent->insertBefore($childNode->cloneNode(true), $tceformsElement); | ||
} | ||
|
||
// Remove the <TCEforms> element | ||
$parent->removeChild($tceformsElement); | ||
$hasChanged = true; | ||
} | ||
|
||
return $hasChanged; | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Remove TCEForms key from all elements in data structure', [new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
<T3DataStructure> | ||
<ROOT> | ||
<TCEforms> | ||
<sheetTitle>aTitle</sheetTitle> | ||
</TCEforms> | ||
<type>array</type> | ||
<el> | ||
<aFlexField> | ||
<TCEforms> | ||
<label>aFlexFieldLabel</label> | ||
<config> | ||
<type>input</type> | ||
</config> | ||
</TCEforms> | ||
</aFlexField> | ||
</el> | ||
</ROOT> | ||
</T3DataStructure> | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
<T3DataStructure> | ||
<ROOT> | ||
<sheetTitle>aTitle</sheetTitle> | ||
<type>array</type> | ||
<el> | ||
<aFlexField> | ||
<label>aFlexFieldLabel</label> | ||
<config> | ||
<type>input</type> | ||
</config> | ||
</aFlexField> | ||
</el> | ||
</ROOT> | ||
</T3DataStructure> | ||
CODE_SAMPLE | ||
)]); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/Rector/v12/v0/flexform/RemoveElementTceFormsRector/Fixture/fixture.xml.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,65 @@ | ||
<T3DataStructure> | ||
<sheets> | ||
<sDEF> | ||
<ROOT> | ||
<TCEforms> | ||
<sheetTitle> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_tab.settings | ||
</sheetTitle> | ||
</TCEforms> | ||
<type>array</type> | ||
<el> | ||
<settings.a> | ||
<TCEforms> | ||
<label> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.a | ||
</label> | ||
<config> | ||
<todo>TODO</todo> | ||
</config> | ||
</TCEforms> | ||
</settings.a> | ||
<settings.b> | ||
<TCEforms> | ||
<label> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.b | ||
</label> | ||
<config> | ||
<todo>TODO</todo> | ||
</config> | ||
</TCEforms> | ||
</settings.b> | ||
</el> | ||
</ROOT> | ||
</sDEF> | ||
</sheets> | ||
</T3DataStructure> | ||
----- | ||
<T3DataStructure> | ||
<sheets> | ||
<sDEF> | ||
<ROOT> | ||
<sheetTitle> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_tab.settings | ||
</sheetTitle> | ||
<type>array</type> | ||
<el> | ||
<settings.a> | ||
<label> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.a | ||
</label><config> | ||
<todo>TODO</todo> | ||
</config> | ||
</settings.a> | ||
<settings.b> | ||
<label> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.b | ||
</label><config> | ||
<todo>TODO</todo> | ||
</config> | ||
</settings.b> | ||
</el> | ||
</ROOT> | ||
</sDEF> | ||
</sheets> | ||
</T3DataStructure> |
22 changes: 22 additions & 0 deletions
22
tests/Rector/v12/v0/flexform/RemoveElementTceFormsRector/Fixture/flexforms_no_change.xml.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,22 @@ | ||
<T3DataStructure> | ||
<sheets> | ||
<sDEF> | ||
<ROOT> | ||
<sheetTitle> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_tab.settings | ||
</sheetTitle> | ||
<type>array</type> | ||
<el> | ||
<settings.topNewsRestriction> | ||
<label> | ||
LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.topNewsRestriction | ||
</label> | ||
<config> | ||
<todo>TODO</todo> | ||
</config> | ||
</settings.topNewsRestriction> | ||
</el> | ||
</ROOT> | ||
</sDEF> | ||
</sheets> | ||
</T3DataStructure> |
32 changes: 32 additions & 0 deletions
32
tests/Rector/v12/v0/flexform/RemoveElementTceFormsRector/RemoveElementTceFormsRectorTest.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\flexform\RemoveElementTceFormsRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class RemoveElementTceFormsRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.xml.inc'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v0/flexform/RemoveElementTceFormsRector/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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Ssch\TYPO3Rector\Rector\v12\v0\flexform\RemoveElementTceFormsRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php'); | ||
$rectorConfig->rule(RemoveElementTceFormsRector::class); | ||
}; |