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
|
|
|
* @validate NotEmpty |
55
|
|
|
*/ |
56
|
|
|
protected $supportedFields; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \Romm\Formz\Form\Definition\Step\Step\Substep\Substeps |
60
|
|
|
*/ |
61
|
|
|
protected $substeps; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function getIdentifier() |
67
|
|
|
{ |
68
|
|
|
return $this->getArrayIndex(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
|
|
public function getPageUid() |
75
|
|
|
{ |
76
|
|
|
return $this->pageUid; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getExtension() |
83
|
|
|
{ |
84
|
|
|
return $this->extension; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getController() |
91
|
|
|
{ |
92
|
|
|
return $this->controller; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getAction() |
99
|
|
|
{ |
100
|
|
|
return $this->action; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return SupportedField[] |
105
|
|
|
*/ |
106
|
|
|
public function getSupportedFields() |
107
|
|
|
{ |
108
|
|
|
return $this->supportedFields; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param Field $field |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function supportsField(Field $field) |
116
|
|
|
{ |
117
|
|
|
foreach ($this->supportedFields as $supportedField) { |
118
|
|
|
if ($supportedField->getField() === $field) { |
119
|
|
|
return true; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
public function hasSubsteps() |
130
|
|
|
{ |
131
|
|
|
return $this->substeps instanceof Substeps; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return Substeps |
136
|
|
|
*/ |
137
|
|
|
public function getSubsteps() |
138
|
|
|
{ |
139
|
|
|
return $this->substeps; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* This function will parse the configuration for `supportedFields`: instead |
144
|
|
|
* of being forced to fill the `fieldName` option for each entry, the field |
145
|
|
|
* key of the entry can be the actual name of the field, and the value of |
146
|
|
|
* the entry can be anything but an array. |
147
|
|
|
* |
148
|
|
|
* @param DataPreProcessor $processor |
149
|
|
|
*/ |
150
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
151
|
|
|
{ |
152
|
|
|
$data = $processor->getData(); |
153
|
|
|
|
154
|
|
|
$supportedFields = (isset($data['supportedFields'])) |
155
|
|
|
? $data['supportedFields'] |
156
|
|
|
: []; |
157
|
|
|
|
158
|
|
|
foreach ($supportedFields as $key => $supportedField) { |
159
|
|
|
$supportedField = is_array($supportedField) |
160
|
|
|
? $supportedField |
161
|
|
|
: []; |
162
|
|
|
$supportedField['fieldName'] = $key; |
163
|
|
|
|
164
|
|
|
$supportedFields[$key] = $supportedField; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$data['supportedFields'] = $supportedFields; |
168
|
|
|
|
169
|
|
|
$processor->setData($data); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|