|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aoe\FeatureFlag\System\Typo3; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2021 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
|
29
|
|
|
|
|
30
|
|
|
class TcaPostProcessor |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Add feature-flag-fields to TCA-fields of DB-tables which support feature-flags |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $tca |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function postProcessTca(array $tca) |
|
39
|
|
|
{ |
|
40
|
|
|
$GLOBALS['TCA'] = $tca; |
|
41
|
|
|
|
|
42
|
|
|
foreach ($this->getTcaTablesWithFeatureFlagSupport() as $table) { |
|
43
|
|
|
ExtensionManagementUtility::addTCAcolumns( |
|
44
|
|
|
$table, |
|
45
|
|
|
[ |
|
46
|
|
|
'tx_featureflag_info' => [ |
|
47
|
|
|
'exclude' => 1, |
|
48
|
|
|
'label' => 'LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:tx_featureflag_info.label', |
|
49
|
|
|
'config' => [ |
|
50
|
|
|
'type' => 'user', |
|
51
|
|
|
'renderType' => 'infoText', |
|
52
|
|
|
] |
|
53
|
|
|
], |
|
54
|
|
|
'tx_featureflag_flag' => [ |
|
55
|
|
|
'exclude' => 1, |
|
56
|
|
|
'label' => 'LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:tx_featureflag_flag', |
|
57
|
|
|
'config' => [ |
|
58
|
|
|
'type' => 'user', |
|
59
|
|
|
'renderType' => 'selectFeatureFlag', |
|
60
|
|
|
'size' => 1, |
|
61
|
|
|
] |
|
62
|
|
|
], |
|
63
|
|
|
'tx_featureflag_behavior' => [ |
|
64
|
|
|
'exclude' => 1, |
|
65
|
|
|
'label' => 'LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:tx_featureflag_behavior', |
|
66
|
|
|
'config' => [ |
|
67
|
|
|
'type' => 'user', |
|
68
|
|
|
'renderType' => 'selectFeatureFlagBehaviour', |
|
69
|
|
|
'size' => 1, |
|
70
|
|
|
] |
|
71
|
|
|
] |
|
72
|
|
|
] |
|
73
|
|
|
); |
|
74
|
|
|
ExtensionManagementUtility::addToAllTCAtypes( |
|
75
|
|
|
$table, |
|
76
|
|
|
' |
|
77
|
|
|
--div--;LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:feature_flag, |
|
78
|
|
|
tx_featureflag_info, tx_featureflag_flag, tx_featureflag_behavior |
|
79
|
|
|
' |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$tca = $GLOBALS['TCA']; |
|
84
|
|
|
return [$tca]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
private function getTcaTablesWithFeatureFlagSupport() |
|
91
|
|
|
{ |
|
92
|
|
|
if (class_exists('TYPO3\\CMS\\Core\\Configuration\\ExtensionConfiguration')) { |
|
93
|
|
|
$config = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
|
94
|
|
|
"TYPO3\\CMS\\Core\\Configuration\\ExtensionConfiguration" |
|
95
|
|
|
)->get('feature_flag'); |
|
96
|
|
|
} else { |
|
97
|
|
|
$config = unserialize( |
|
98
|
|
|
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['feature_flag'], |
|
99
|
|
|
['allowed_classes' => false] |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if (isset($config['tables'])) { |
|
104
|
|
|
return explode(',', $config ['tables']); |
|
105
|
|
|
} |
|
106
|
|
|
return []; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|