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
|
|
|
'userFunc' => 'Aoe\FeatureFlag\System\Typo3\TCA->renderInfo', |
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
|
|
|
'userFunc' => 'Aoe\FeatureFlag\System\Typo3\TCA->renderSelectForFlag', |
60
|
|
|
] |
61
|
|
|
], |
62
|
|
|
'tx_featureflag_behavior' => [ |
63
|
|
|
'exclude' => 1, |
64
|
|
|
'label' => 'LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:tx_featureflag_behavior', |
65
|
|
|
'config' => [ |
66
|
|
|
'type' => 'user', |
67
|
|
|
'userFunc' => 'Aoe\FeatureFlag\System\Typo3\TCA->renderSelectForBehavior', |
68
|
|
|
] |
69
|
|
|
] |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
$GLOBALS['TCA'][$table]['palettes']['tx_featureflag'] = ['showitem' => 'tx_featureflag_flag,tx_featureflag_behavior']; |
73
|
|
|
ExtensionManagementUtility::addToAllTCAtypes( |
74
|
|
|
$table, |
75
|
|
|
'--div--;LLL:EXT:feature_flag/Resources/Private/Language/locallang_db.xml:feature_flag,tx_featureflag_info,--palette--;;tx_featureflag' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$tca = $GLOBALS['TCA']; |
80
|
|
|
return [$tca]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
private function getTcaTablesWithFeatureFlagSupport() |
87
|
|
|
{ |
88
|
|
|
if (class_exists('TYPO3\\CMS\\Core\\Configuration\\ExtensionConfiguration')) { |
89
|
|
|
$config = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
90
|
|
|
"TYPO3\\CMS\\Core\\Configuration\\ExtensionConfiguration" |
91
|
|
|
)->get('feature_flag'); |
92
|
|
|
} else { |
93
|
|
|
$config = unserialize( |
94
|
|
|
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['feature_flag'], |
95
|
|
|
['allowed_classes' => false] |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (isset($config['tables'])) { |
100
|
|
|
return explode(',', $config ['tables']); |
101
|
|
|
} |
102
|
|
|
return []; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|