Completed
Push — middleware-wip ( f2f782...846df6 )
by Romain
10:35 queued 04:40
created

Step::getSubSteps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Form\Definition\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\Form\Definition\AbstractFormDefinition;
21
use Romm\Formz\Form\Definition\Field\Field;
22
use Romm\Formz\Form\Definition\Step\Step\SubStep\SubSteps;
23
24
class Step extends AbstractFormDefinition implements DataPreProcessorInterface
25
{
26
    use ParentsTrait;
27
    use StoreArrayIndexTrait;
28
29
    /**
30
     * @var int
31
     * @validate IntegerValidator
32
     * @validate Romm.Formz:PageExists
33
     */
34
    protected $pageUid;
35
36
    /**
37
     * @var string
38
     */
39
    protected $extension;
40
41
    /**
42
     * @var string
43
     */
44
    protected $controller;
45
46
    /**
47
     * @var string
48
     * @validate NotEmpty
49
     */
50
    protected $action;
51
52
    /**
53
     * @var \Romm\Formz\Form\Definition\Step\Step\SupportedField[]
54
     */
55
    protected $supportedFields;
56
57
    /**
58
     * @var \Romm\Formz\Form\Definition\Step\Step\SubStep\SubSteps
59
     */
60
    protected $subSteps;
61
62
    /**
63
     * @return string
64
     */
65
    public function getName()
66
    {
67
        return $this->getArrayIndex();
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getPageUid()
74
    {
75
        return $this->pageUid;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getExtension()
82
    {
83
        return $this->extension;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getController()
90
    {
91
        return $this->controller;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getAction()
98
    {
99
        return $this->action;
100
    }
101
102
    /**
103
     * @return SupportedField[]
104
     */
105
    public function getSupportedFields()
106
    {
107
        return $this->supportedFields;
108
    }
109
110
    /**
111
     * @param Field $field
112
     * @return bool
113
     */
114
    public function supportsField(Field $field)
115
    {
116
        foreach ($this->supportedFields as $supportedField) {
117
            if ($supportedField->getField() === $field) {
118
                return true;
119
            }
120
        }
121
122
        return false;
123
    }
124
125
    /**
126
     * @return SubSteps
127
     */
128
    public function getSubSteps()
129
    {
130
        return $this->subSteps;
131
    }
132
133
    /**
134
     * This function will parse the configuration for `supportedFields`: instead
135
     * of being forced to fill the `fieldName` option for each entry, the field
136
     * key of the entry can be the actual name of the field, and the value of
137
     * the entry can be anything but an array.
138
     *
139
     * @param DataPreProcessor $processor
140
     */
141
    public static function dataPreProcessor(DataPreProcessor $processor)
142
    {
143
        $data = $processor->getData();
144
145
        $supportedFields = (isset($data['supportedFields']))
146
            ? $data['supportedFields']
147
            : [];
148
149
        foreach ($supportedFields as $key => $supportedField) {
150
            $supportedField = is_array($supportedField)
151
                ? $supportedField
152
                : [];
153
            $supportedField['fieldName'] = $key;
154
155
            $supportedFields[$key] = $supportedField;
156
        }
157
158
        $data['supportedFields'] = $supportedFields;
159
160
        $processor->setData($data);
161
    }
162
}
163