Passed
Push — main ( 400cf4...75e45b )
by Felix
03:05
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
    /**
38
     * @return array As defined in initializeResultArray() of AbstractNode
39
     */
40 1
    public function render()
41
    {
42
        $propertyArray = [
43 1
            'table' => $this->data['tableName'],
44 1
            'field' => $this->data['fieldName'],
45 1
            'row' => $this->data['databaseRow'],
46
        ];
47
48
        // check, which behavior is selected
49 1
        $isBehaviorHideSelected = false;
50 1
        $isBehaviorShowSelected = false;
51 1
        $activeMapping = $this->mappingRepository->findOneByForeignTableNameAndUid(
52 1
            $propertyArray['row']['uid'],
53 1
            $propertyArray['table']
54
        );
55 1
        if ($activeMapping instanceof Mapping) {
0 ignored issues
show
introduced by
$activeMapping is always a sub-type of Aoe\FeatureFlag\Domain\Model\Mapping.
Loading history...
56 1
            if ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_HIDE) {
57
                $isBehaviorHideSelected = true;
58 1
            } elseif ($activeMapping->getBehavior() === FeatureFlagService::BEHAVIOR_SHOW) {
59 1
                $isBehaviorShowSelected = true;
60
            }
61
        }
62
63
        $optionElements = [
64
            [
65 1
                'name' => $this->getLanguageService()
66 1
                    ->sL('LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.hide'),
67
                'value' => FeatureFlagService::BEHAVIOR_HIDE,
68 1
                'isSelected' => $isBehaviorHideSelected,
69
            ],
70
            [
71 1
                'name' => $this->getLanguageService()
72 1
                    ->sL('LLL:EXT:feature_flag/Resources/Private/Language/locallang.xlf:tx_featureflag_behavior.show'),
73
                'value' => FeatureFlagService::BEHAVIOR_SHOW,
74 1
                'isSelected' => $isBehaviorShowSelected,
75
            ],
76
        ];
77
78 1
        return $this->renderElement($optionElements);
79
    }
80
}
81