Passed
Push — main ( 9b4de3...46b341 )
by Felix
02:33
created

FeatureFlagFormSelectElement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 17
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 38 4
1
<?php
2
namespace Aoe\FeatureFlag\Form\Element;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2021 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use Aoe\FeatureFlag\Domain\Model\FeatureFlag;
29
use Aoe\FeatureFlag\Domain\Model\Mapping;
30
31
/**
32
 * This is rendered for type=user, renderType=selectFeatureFlag
33
 */
34
class FeatureFlagFormSelectElement extends AbstractFormSelectElement
35
{
36
    /**
37
     * @return array As defined in initializeResultArray() of AbstractNode
38
     */
39
    public function render()
40
    {
41
        $propertyArray = [
42
            'table' => $this->data['tableName'],
43
            'field' => $this->data['fieldName'],
44
            'row' => $this->data['databaseRow']
45
        ];
46
47
        $activeMapping = $this->mappingRepository->findOneByForeignTableNameAndUid(
48
            $propertyArray['row']['uid'],
49
            $propertyArray['table']
50
        );
51
52
        $optionElements = [
53
            [
54
                'name' => '',
55
                'value' => 0,
56
                'isSelected' => false
57
            ]
58
        ];
59
60
        foreach ($this->featureFlagRepository->findAll() as $featureFlag) {
61
            /** @var FeatureFlag $featureFlag */
62
            $selected = false;
63
            if ($activeMapping instanceof Mapping &&
64
                $activeMapping->getFeatureFlag()->getUid() === $featureFlag->getUid()
65
            ) {
66
                $selected = true;
67
            }
68
69
            $optionElements[] = [
70
                'name' => $featureFlag->getDescription(),
71
                'value' => $featureFlag->getUid(),
72
                'isSelected' => $selected
73
            ];
74
        }
75
76
        return $this->renderElement($optionElements);
77
    }
78
}
79