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\FormObject; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Core\Core; |
17
|
|
|
use Romm\Formz\Domain\Model\FormMetadata; |
18
|
|
|
use Romm\Formz\Error\FormResult; |
19
|
|
|
use Romm\Formz\Form\Definition\Step\Step\Step; |
20
|
|
|
use Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition; |
21
|
|
|
use Romm\Formz\Form\FormInterface; |
22
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectMetadata; |
23
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectRequestData; |
24
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectSteps; |
25
|
|
|
use Romm\Formz\Form\FormObject\Service\Step\FormStepPersistence; |
26
|
|
|
use Romm\Formz\Service\HashService; |
27
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\Request; |
28
|
|
|
|
29
|
|
|
class FormObjectProxy |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var FormObject |
33
|
|
|
*/ |
34
|
|
|
protected $formObject; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var FormInterface |
38
|
|
|
*/ |
39
|
|
|
protected $form; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $formHash; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var bool |
48
|
|
|
*/ |
49
|
|
|
protected $formWasSubmitted = false; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var bool |
53
|
|
|
*/ |
54
|
|
|
protected $formWasValidated = false; |
55
|
|
|
/** |
56
|
|
|
* @var FormResult |
57
|
|
|
*/ |
58
|
|
|
protected $formResult; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var FormObjectRequestData |
62
|
|
|
*/ |
63
|
|
|
protected $requestData; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var FormObjectMetadata |
67
|
|
|
*/ |
68
|
|
|
protected $metadata; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
protected $formIsPersistent = false; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var FormObjectSteps |
77
|
|
|
*/ |
78
|
|
|
protected $stepService; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param FormObject $formObject |
82
|
|
|
* @param FormInterface $form |
83
|
|
|
*/ |
84
|
|
|
public function __construct(FormObject $formObject, FormInterface $form) |
85
|
|
|
{ |
86
|
|
|
$this->formObject = $formObject; |
87
|
|
|
$this->form = $form; |
88
|
|
|
$this->stepService = Core::instantiate(FormObjectSteps::class, $formObject); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return FormInterface |
93
|
|
|
*/ |
94
|
|
|
public function getForm() |
95
|
|
|
{ |
96
|
|
|
return $this->form; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Will mark the form as submitted (change the result returned by the |
101
|
|
|
* function `formWasSubmitted()`). |
102
|
|
|
* |
103
|
|
|
* @internal |
104
|
|
|
*/ |
105
|
|
|
public function markFormAsSubmitted() |
106
|
|
|
{ |
107
|
|
|
$this->formWasSubmitted = true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns `true` if the form was submitted by the user. |
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function formWasSubmitted() |
116
|
|
|
{ |
117
|
|
|
return $this->formWasSubmitted; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Marks the form as validated. |
122
|
|
|
* |
123
|
|
|
* @internal |
124
|
|
|
*/ |
125
|
|
|
public function markFormAsValidated() |
126
|
|
|
{ |
127
|
|
|
$this->formWasValidated = true; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return bool |
132
|
|
|
*/ |
133
|
|
|
public function formWasValidated() |
134
|
|
|
{ |
135
|
|
|
return $this->formWasValidated; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @internal |
140
|
|
|
*/ |
141
|
|
|
public function markFormAsPersistent() |
142
|
|
|
{ |
143
|
|
|
$this->formIsPersistent = true; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
|
|
public function formIsPersistent() |
150
|
|
|
{ |
151
|
|
|
return $this->formIsPersistent; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return FormResult |
156
|
|
|
*/ |
157
|
|
|
public function getFormResult() |
158
|
|
|
{ |
159
|
|
|
if (null === $this->formResult) { |
160
|
|
|
$this->formResult = new FormResult; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $this->formResult; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return FormObjectRequestData |
168
|
|
|
*/ |
169
|
|
|
public function getRequestData() |
170
|
|
|
{ |
171
|
|
|
return $this->requestData; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return FormMetadata |
176
|
|
|
*/ |
177
|
|
|
public function getFormMetadata() |
178
|
|
|
{ |
179
|
|
|
if (null === $this->metadata) { |
180
|
|
|
$this->metadata = Core::instantiate(FormObjectMetadata::class, $this->formObject); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return $this->metadata->getMetadata(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return Step|null |
188
|
|
|
*/ |
189
|
|
|
public function getCurrentStep() |
190
|
|
|
{ |
191
|
|
|
return $this->stepService->getCurrentStep(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param Request $request |
196
|
|
|
*/ |
197
|
|
|
public function fetchCurrentStep(Request $request) |
198
|
|
|
{ |
199
|
|
|
$this->stepService->fetchCurrentStep($request); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return SubstepDefinition |
204
|
|
|
*/ |
205
|
|
|
public function getCurrentSubstepDefinition() |
206
|
|
|
{ |
207
|
|
|
return $this->stepService->getCurrentSubstepDefinition(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param SubstepDefinition $currentSubstepDefinition |
212
|
|
|
*/ |
213
|
|
|
public function setCurrentSubstepDefinition(SubstepDefinition $currentSubstepDefinition) |
214
|
|
|
{ |
215
|
|
|
$this->stepService->setCurrentSubstepDefinition($currentSubstepDefinition); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return FormStepPersistence |
220
|
|
|
*/ |
221
|
|
|
public function getStepPersistence() |
222
|
|
|
{ |
223
|
|
|
return $this->stepService->getStepPersistence(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return string |
228
|
|
|
*/ |
229
|
|
|
public function getFormHash() |
230
|
|
|
{ |
231
|
|
|
if (null === $this->formHash) { |
232
|
|
|
$this->formHash = HashService::get()->getHash(uniqid(get_class($this->form))); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return $this->formHash; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param string $hash |
240
|
|
|
*/ |
241
|
|
|
public function setFormHash($hash) |
242
|
|
|
{ |
243
|
|
|
$this->formHash = $hash; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param FormObjectRequestData $requestData |
248
|
|
|
*/ |
249
|
|
|
public function injectRequestData(FormObjectRequestData $requestData) |
250
|
|
|
{ |
251
|
|
|
$this->requestData = $requestData; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|