Completed
Push — middleware-wip ( 6cd994...b65ea9 )
by Romain
07:11
created

Step::supportsField()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Configuration\Form\Step\Step;
15
16
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
17
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
18
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait;
19
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait;
20
use Romm\Formz\Configuration\AbstractFormzConfiguration;
21
use Romm\Formz\Configuration\Form\Field\Field;
22
23
class Step extends AbstractFormzConfiguration implements DataPreProcessorInterface
24
{
25
    use ParentsTrait;
26
    use StoreArrayIndexTrait;
27
28
    /**
29
     * @var int
30
     * @validate IntegerValidator
31
     * @validate Romm.Formz:PageExists
32
     */
33
    protected $pageUid;
34
35
    /**
36
     * @var string
37
     */
38
    protected $extension;
39
40
    /**
41
     * @var string
42
     */
43
    protected $controller;
44
45
    /**
46
     * @var string
47
     * @validate NotEmpty
48
     */
49
    protected $action;
50
51
    /**
52
     * @var \Romm\Formz\Configuration\Form\Step\Step\SupportedField[]
53
     */
54
    protected $supportedFields;
55
56
    /**
57
     * @return string
58
     */
59
    public function getName()
60
    {
61
        return $this->getArrayIndex();
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getPageUid()
68
    {
69
        return $this->pageUid;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getExtension()
76
    {
77
        return $this->extension;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getController()
84
    {
85
        return $this->controller;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getAction()
92
    {
93
        return $this->action;
94
    }
95
96
    /**
97
     * @return SupportedField[]
98
     */
99
    public function getSupportedFields()
100
    {
101
        return $this->supportedFields;
102
    }
103
104
    /**
105
     * @param Field $field
106
     * @return bool
107
     */
108
    public function supportsField(Field $field)
109
    {
110
        foreach ($this->supportedFields as $supportedField) {
111
            if ($supportedField->getField() === $field) {
112
                return true;
113
            }
114
        }
115
116
        return false;
117
    }
118
119
    /**
120
     * @todo
121
     *
122
     * @param DataPreProcessor $processor
123
     */
124
    public static function dataPreProcessor(DataPreProcessor $processor)
125
    {
126
        $data = $processor->getData();
127
128
        $supportedFields = (isset($data['supportedFields']))
129
            ? $data['supportedFields']
130
            : [];
131
132
        foreach ($supportedFields as $key => $supportedField) {
133
            $supportedField = is_array($supportedField)
134
                ? $supportedField
135
                : [];
136
            $supportedField['fieldName'] = $key;
137
138
            $supportedFields[$key] = $supportedField;
139
        }
140
141
        $data['supportedFields'] = $supportedFields;
142
143
        $processor->setData($data);
144
    }
145
}
146