Passed
Push — main ( cdbc18...f1cdfe )
by
unknown
02:56
created

FeatureFlagBehaviourFormSelectElement::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 39
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4.0016

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 24
nc 4
nop 0
dl 0
loc 39
ccs 20
cts 21
cp 0.9524
crap 4.0016
rs 9.536
c 1
b 0
f 0
1
<?php
2
3
namespace Aoe\FeatureFlag\Form\Element;
4
5
use Aoe\FeatureFlag\Domain\Model\Mapping;
6
use Aoe\FeatureFlag\Service\FeatureFlagService;
7
8
/***************************************************************
9
 *  Copyright notice
10
 *
11
 *  (c) 2021 AOE GmbH <[email protected]>
12
 *
13
 *  All rights reserved
14
 *
15
 *  This script is part of the TYPO3 project. The TYPO3 project is
16
 *  free software; you can redistribute it and/or modify
17
 *  it under the terms of the GNU General Public License as published by
18
 *  the Free Software Foundation; either version 3 of the License, or
19
 *  (at your option) any later version.
20
 *
21
 *  The GNU General Public License can be found at
22
 *  http://www.gnu.org/copyleft/gpl.html.
23
 *
24
 *  This script is distributed in the hope that it will be useful,
25
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 *  GNU General Public License for more details.
28
 *
29
 *  This copyright notice MUST APPEAR in all copies of the script!
30
 ***************************************************************/
31
32
/**
33
 * This is rendered for type=user, renderType=selectFeatureFlagBehaviour
34
 */
35
class FeatureFlagBehaviourFormSelectElement extends AbstractFormSelectElement
36
{
37 1
    public function render(): array
38
    {
39
        $propertyArray = [
40 1
            'table' => $this->data['tableName'],
41 1
            'field' => $this->data['fieldName'],
42 1
            'row' => $this->data['databaseRow'],
43
        ];
44
45
        // check, which behavior is selected
46 1
        $isBehaviorHideSelected = false;
47 1
        $isBehaviorShowSelected = false;
48 1
        $activeMapping = $this->mappingRepository->findOneByForeignTableNameAndUid(
49 1
            $propertyArray['row']['uid'],
50 1
            $propertyArray['table']
51
        );
52 1
        if ($activeMapping instanceof Mapping) {
53 1
            if ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_HIDE) {
54
                $isBehaviorHideSelected = true;
55 1
            } elseif ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_SHOW) {
56 1
                $isBehaviorShowSelected = true;
57
            }
58
        }
59
60
        $optionElements = [
61
            [
62 1
                'name' => $this->getLanguageService()
63 1
                    ->sL('LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.hide'),
64
                'value' => FeatureFlagService::BEHAVIOR_HIDE,
65 1
                'isSelected' => $isBehaviorHideSelected,
66
            ],
67
            [
68 1
                'name' => $this->getLanguageService()
69 1
                    ->sL('LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.show'),
70
                'value' => FeatureFlagService::BEHAVIOR_SHOW,
71 1
                'isSelected' => $isBehaviorShowSelected,
72
            ],
73
        ];
74
75 1
        return $this->renderElement($optionElements);
76
    }
77
}
78