Passed
Branch main (a47c5a)
by AOEPeople
15:53 queued 02:59
created

Tx_FeatureFlag_TcaPostProcessor::postProcessTca()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

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