-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
MigrateRootUidToStartingPointsRector.php
107 lines (93 loc) · 3.21 KB
/
MigrateRootUidToStartingPointsRector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
namespace Ssch\TYPO3Rector\TYPO311\v4;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Scalar\String_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v11\v4\MigrateRootUidToStartingPointsRector\MigrateRootUidToStartingPointsRectorTest
*/
final class MigrateRootUidToStartingPointsRector extends AbstractTcaRector implements DocumentedRuleInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'If a column has [treeConfig][rootUid] defined, migrate to [treeConfig][startingPoints] on the same level.',
[
new CodeSample(
<<<'CODE_SAMPLE'
return [
'columns' => [
'aField' => [
'config' => [
'type' => 'select',
'renderType' => 'selectTree',
'treeConfig' => [
'rootUid' => 42
],
],
],
],
];
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
return [
'columns' => [
'aField' => [
'config' => [
'type' => 'select',
'renderType' => 'selectTree',
'treeConfig' => [
'startingPoints' => '42'
],
],
],
],
];
CODE_SAMPLE
),
]
);
}
protected function refactorColumn(Expr $columnName, Expr $columnTca): void
{
$configArray = $this->extractSubArrayByKey($columnTca, self::CONFIG);
if (! $configArray instanceof Array_) {
return;
}
// Fetch type
if (! $this->isConfigType($configArray, 'select') && ! $this->isConfigType($configArray, 'category')) {
return;
}
$treeConfigArray = $this->extractSubArrayByKey($configArray, 'treeConfig');
if (! $treeConfigArray instanceof Array_) {
return;
}
if ($this->hasKey($configArray, 'treeConfig')) {
$treeConfigArrayItem = $this->extractArrayItemByKey($configArray, 'treeConfig');
if (! $treeConfigArrayItem instanceof ArrayItem) {
return;
}
$rootUidArrayItem = $this->extractArrayItemByKey($treeConfigArray, 'rootUid');
if (! $rootUidArrayItem instanceof ArrayItem) {
return;
}
$rootUidValue = $this->valueResolver->getValue($rootUidArrayItem->value);
if ($rootUidValue === 0) {
return;
}
$treeConfigArray->items[] = new ArrayItem(new String_((string) $rootUidValue), new String_(
'startingPoints'
));
}
$this->removeArrayItemFromArrayByKey($treeConfigArray, 'rootUid');
$this->hasAstBeenChanged = true;
}
}