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\Substep; |
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
|
|
|
/** |
57
|
|
|
* @var FormResult |
58
|
|
|
*/ |
59
|
|
|
protected $formResult; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var FormObjectRequestData |
63
|
|
|
*/ |
64
|
|
|
protected $requestData; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var FormObjectMetadata |
68
|
|
|
*/ |
69
|
|
|
protected $metadata; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var FormObjectSteps |
73
|
|
|
*/ |
74
|
|
|
protected $stepService; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param FormObject $formObject |
78
|
|
|
* @param FormInterface $form |
79
|
|
|
*/ |
80
|
|
|
public function __construct(FormObject $formObject, FormInterface $form) |
81
|
|
|
{ |
82
|
|
|
$this->formObject = $formObject; |
83
|
|
|
$this->form = $form; |
84
|
|
|
$this->stepService = Core::instantiate(FormObjectSteps::class, $formObject); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return FormInterface |
89
|
|
|
*/ |
90
|
|
|
public function getForm() |
91
|
|
|
{ |
92
|
|
|
return $this->form; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Will mark the form as submitted (change the result returned by the |
97
|
|
|
* function `formWasSubmitted()`). |
98
|
|
|
*/ |
99
|
|
|
public function markFormAsSubmitted() |
100
|
|
|
{ |
101
|
|
|
$this->formWasSubmitted = true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns `true` if the form was submitted by the user. |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function formWasSubmitted() |
110
|
|
|
{ |
111
|
|
|
return $this->formWasSubmitted; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Marks the form as validated. |
116
|
|
|
*/ |
117
|
|
|
public function markFormAsValidated() |
118
|
|
|
{ |
119
|
|
|
$this->formWasValidated = true; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return bool |
124
|
|
|
*/ |
125
|
|
|
public function formWasValidated() |
126
|
|
|
{ |
127
|
|
|
return $this->formWasValidated; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return FormResult |
132
|
|
|
*/ |
133
|
|
|
public function getFormResult() |
134
|
|
|
{ |
135
|
|
|
if (null === $this->formResult) { |
136
|
|
|
$this->formResult = new FormResult; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $this->formResult; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return FormObjectRequestData |
144
|
|
|
*/ |
145
|
|
|
public function getRequestData() |
146
|
|
|
{ |
147
|
|
|
return $this->requestData; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return FormMetadata |
152
|
|
|
*/ |
153
|
|
|
public function getFormMetadata() |
154
|
|
|
{ |
155
|
|
|
if (null === $this->metadata) { |
156
|
|
|
$formObject = FormObjectFactory::get()->getInstanceWithFormInstance($this->form); |
157
|
|
|
$this->metadata = Core::instantiate(FormObjectMetadata::class, $formObject); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $this->metadata->getMetadata(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param Request $request |
165
|
|
|
* @return Step|null |
166
|
|
|
*/ |
167
|
|
|
public function getCurrentStep(Request $request) |
168
|
|
|
{ |
169
|
|
|
return $this->stepService->getCurrentStep($request); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return Substep|null |
174
|
|
|
*/ |
175
|
|
|
public function getCurrentSubstep() |
176
|
|
|
{ |
177
|
|
|
return $this->formObject->getDefinition()->getSteps()->getFirstStepDefinition()->getStep()->getSubsteps()->getFirstSubstepDefinition()->getSubstep(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return FormStepPersistence |
182
|
|
|
*/ |
183
|
|
|
public function getStepPersistence() |
184
|
|
|
{ |
185
|
|
|
return $this->stepService->getStepPersistence(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getFormHash() |
192
|
|
|
{ |
193
|
|
|
if (null === $this->formHash) { |
194
|
|
|
$this->formHash = HashService::get()->getHash(uniqid(get_class($this->form))); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
return $this->formHash; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $hash |
202
|
|
|
*/ |
203
|
|
|
public function setFormHash($hash) |
204
|
|
|
{ |
205
|
|
|
$this->formHash = $hash; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param FormObjectRequestData $requestData |
210
|
|
|
*/ |
211
|
|
|
public function injectRequestData(FormObjectRequestData $requestData) |
212
|
|
|
{ |
213
|
|
|
$this->requestData = $requestData; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|