Passed
Push — main ( 98505c...b09cff )
by
unknown
14:24 queued 11:28
created

TcaPostProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 4
eloc 35
dl 0
loc 59
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

2 Methods

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