-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
FormInterface.php
289 lines (256 loc) · 9.26 KB
/
FormInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
/**
* A form group bundling multiple forms in a hierarchical structure.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @extends \ArrayAccess<string, FormInterface>
* @extends \Traversable<string, FormInterface>
*/
interface FormInterface extends \ArrayAccess, \Traversable, \Countable
{
/**
* Sets the parent form.
*
* @param FormInterface|null $parent The parent form or null if it's the root
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
* @throws Exception\LogicException when trying to set a parent for a form with
* an empty name
*/
public function setParent(?self $parent): static;
/**
* Returns the parent form.
*/
public function getParent(): ?self;
/**
* Adds or replaces a child to the form.
*
* @param FormInterface|string $child The FormInterface instance or the name of the child
* @param string|null $type The child's type, if a name was passed
* @param array $options The child's options, if a name was passed
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
* @throws Exception\LogicException when trying to add a child to a non-compound form
* @throws Exception\UnexpectedTypeException if $child or $type has an unexpected type
*/
public function add(self|string $child, ?string $type = null, array $options = []): static;
/**
* Returns the child with the given name.
*
* @throws Exception\OutOfBoundsException if the named child does not exist
*/
public function get(string $name): self;
/**
* Returns whether a child with the given name exists.
*/
public function has(string $name): bool;
/**
* Removes a child from the form.
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
*/
public function remove(string $name): static;
/**
* Returns all children in this group.
*
* @return self[]
*/
public function all(): array;
/**
* Returns the errors of this form.
*
* @param bool $deep Whether to include errors of child forms as well
* @param bool $flatten Whether to flatten the list of errors in case
* $deep is set to true
*/
public function getErrors(bool $deep = false, bool $flatten = true): FormErrorIterator;
/**
* Updates the form with default model data.
*
* @param mixed $modelData The data formatted as expected for the underlying object
*
* @return $this
*
* @throws Exception\AlreadySubmittedException If the form has already been submitted
* @throws Exception\LogicException if the view data does not match the expected type
* according to {@link FormConfigInterface::getDataClass}
* @throws Exception\RuntimeException If listeners try to call setData in a cycle or if
* the form inherits data from its parent
* @throws Exception\TransformationFailedException if the synchronization failed
*/
public function setData(mixed $modelData): static;
/**
* Returns the model data in the format needed for the underlying object.
*
* @return mixed When the field is not submitted, the default data is returned.
* When the field is submitted, the default data has been bound
* to the submitted view data.
*
* @throws Exception\RuntimeException If the form inherits data but has no parent
*/
public function getData(): mixed;
/**
* Returns the normalized data of the field, used as internal bridge
* between model data and view data.
*
* @return mixed When the field is not submitted, the default data is returned.
* When the field is submitted, the normalized submitted data
* is returned if the field is synchronized with the view data,
* null otherwise.
*
* @throws Exception\RuntimeException If the form inherits data but has no parent
*/
public function getNormData(): mixed;
/**
* Returns the view data of the field.
*
* It may be defined by {@link FormConfigInterface::getDataClass}.
*
* There are two cases:
*
* - When the form is compound the view data is mapped to the children.
* Each child will use its mapped data as model data.
* It can be an array, an object or null.
*
* - When the form is simple its view data is used to be bound
* to the submitted data.
* It can be a string or an array.
*
* In both cases the view data is the actual altered data on submission.
*
* @throws Exception\RuntimeException If the form inherits data but has no parent
*/
public function getViewData(): mixed;
/**
* Returns the extra submitted data.
*
* @return array The submitted data which do not belong to a child
*/
public function getExtraData(): array;
/**
* Returns the form's configuration.
*/
public function getConfig(): FormConfigInterface;
/**
* Returns whether the form is submitted.
*/
public function isSubmitted(): bool;
/**
* Returns the name by which the form is identified in forms.
*
* Only root forms are allowed to have an empty name.
*/
public function getName(): string;
/**
* Returns the property path that the form is mapped to.
*/
public function getPropertyPath(): ?PropertyPathInterface;
/**
* Adds an error to this form.
*
* @return $this
*/
public function addError(FormError $error): static;
/**
* Returns whether the form and all children are valid.
*
* @throws Exception\LogicException if the form is not submitted
*/
public function isValid(): bool;
/**
* Returns whether the form is required to be filled out.
*
* If the form has a parent and the parent is not required, this method
* will always return false. Otherwise the value set with setRequired()
* is returned.
*/
public function isRequired(): bool;
/**
* Returns whether this form is disabled.
*
* The content of a disabled form is displayed, but not allowed to be
* modified. The validation of modified disabled forms should fail.
*
* Forms whose parents are disabled are considered disabled regardless of
* their own state.
*/
public function isDisabled(): bool;
/**
* Returns whether the form is empty.
*/
public function isEmpty(): bool;
/**
* Returns whether the data in the different formats is synchronized.
*
* If the data is not synchronized, you can get the transformation failure
* by calling {@link getTransformationFailure()}.
*
* If the form is not submitted, this method always returns true.
*/
public function isSynchronized(): bool;
/**
* Returns the data transformation failure, if any, during submission.
*/
public function getTransformationFailure(): ?Exception\TransformationFailedException;
/**
* Initializes the form tree.
*
* Should be called on the root form after constructing the tree.
*
* @return $this
*
* @throws Exception\RuntimeException If the form is not the root
*/
public function initialize(): static;
/**
* Inspects the given request and calls {@link submit()} if the form was
* submitted.
*
* Internally, the request is forwarded to the configured
* {@link RequestHandlerInterface} instance, which determines whether to
* submit the form or not.
*
* @return $this
*/
public function handleRequest(mixed $request = null): static;
/**
* Submits data to the form.
*
* @param string|array|null $submittedData The submitted data
* @param bool $clearMissing Whether to set fields to NULL
* when they are missing in the
* submitted data. This argument
* is only used in compound form
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
*/
public function submit(string|array|null $submittedData, bool $clearMissing = true): static;
/**
* Returns the root of the form tree.
*/
public function getRoot(): self;
/**
* Returns whether the field is the root of the form tree.
*/
public function isRoot(): bool;
public function createView(?FormView $parent = null): FormView;
}