Completed
Push — master ( d535d3...8c6cf6 )
by Felix
16:53
created

Tx_FeatureFlag_TcaPostProcessor::postProcessTca()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 44
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 29
nc 2
nop 1
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
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