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\Formz\Configuration\AbstractFormzConfiguration; |
20
|
|
|
use Romm\Formz\Configuration\Form\Field\Field; |
21
|
|
|
|
22
|
|
|
class Step extends AbstractFormzConfiguration implements DataPreProcessorInterface |
23
|
|
|
{ |
24
|
|
|
use ParentsTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
* @validate NotEmpty |
29
|
|
|
*/ |
30
|
|
|
protected $name; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
* @validate IntegerValidator |
35
|
|
|
* @validate Romm.Formz:PageExists |
36
|
|
|
*/ |
37
|
|
|
protected $pageUid; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $extension; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $controller; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
* @validate NotEmpty |
52
|
|
|
*/ |
53
|
|
|
protected $action; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var \Romm\Formz\Configuration\Form\Step\Step\SupportedField[] |
57
|
|
|
*/ |
58
|
|
|
protected $supportedFields; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var \Romm\Formz\Configuration\Form\Step\Step\NextSteps |
62
|
|
|
*/ |
63
|
|
|
protected $next; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getName() |
69
|
|
|
{ |
70
|
|
|
return $this->name; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function getPageUid() |
77
|
|
|
{ |
78
|
|
|
return $this->pageUid; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getExtension() |
85
|
|
|
{ |
86
|
|
|
return $this->extension; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getController() |
93
|
|
|
{ |
94
|
|
|
return $this->controller; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getAction() |
101
|
|
|
{ |
102
|
|
|
return $this->action; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return SupportedField[] |
107
|
|
|
*/ |
108
|
|
|
public function getSupportedFields() |
109
|
|
|
{ |
110
|
|
|
return $this->supportedFields; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param Field $field |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function supportsField(Field $field) |
118
|
|
|
{ |
119
|
|
|
foreach ($this->supportedFields as $supportedField) { |
120
|
|
|
if ($supportedField->getField() === $field) { |
121
|
|
|
return true; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return false; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
public function hasNextStep() |
132
|
|
|
{ |
133
|
|
|
return null !== $this->next; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return NextSteps |
138
|
|
|
*/ |
139
|
|
|
public function getNextStep() |
140
|
|
|
{ |
141
|
|
|
if (false === $this->hasNextStep()) { |
142
|
|
|
throw new \Exception('todo'); // @todo |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $this->next; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
|
|
public function hasPreviousStep() |
152
|
|
|
{ |
153
|
|
|
return $this->hasParent(self::class); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return Step |
158
|
|
|
*/ |
159
|
|
|
public function getPreviousStep() |
160
|
|
|
{ |
161
|
|
|
if (false === $this->hasPreviousStep()) { |
162
|
|
|
throw new \Exception('todo'); // @todo |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** @var Step $previousStep */ |
166
|
|
|
$previousStep = $this->getFirstParent(self::class); |
167
|
|
|
|
168
|
|
|
return $previousStep; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @todo |
173
|
|
|
* |
174
|
|
|
* @param DataPreProcessor $processor |
175
|
|
|
*/ |
176
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
177
|
|
|
{ |
178
|
|
|
$data = $processor->getData(); |
179
|
|
|
|
180
|
|
|
$supportedFields = (isset($data['supportedFields'])) |
181
|
|
|
? $data['supportedFields'] |
182
|
|
|
: []; |
183
|
|
|
|
184
|
|
|
foreach ($supportedFields as $key => $supportedField) { |
185
|
|
|
$supportedField = is_array($supportedField) |
186
|
|
|
? $supportedField |
187
|
|
|
: []; |
188
|
|
|
$supportedField['fieldName'] = $key; |
189
|
|
|
|
190
|
|
|
$supportedFields[$key] = $supportedField; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$data['supportedFields'] = $supportedFields; |
194
|
|
|
|
195
|
|
|
$processor->setData($data); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|