1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Form\YiisoftFormModel; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Form\Field\Button; |
8
|
|
|
use Yiisoft\Form\Field\ButtonGroup; |
9
|
|
|
use Yiisoft\Form\Field\Checkbox; |
10
|
|
|
use Yiisoft\Form\Field\CheckboxList; |
11
|
|
|
use Yiisoft\Form\Field\Date; |
12
|
|
|
use Yiisoft\Form\Field\DateTime; |
13
|
|
|
use Yiisoft\Form\Field\DateTimeLocal; |
14
|
|
|
use Yiisoft\Form\Field\Email; |
15
|
|
|
use Yiisoft\Form\YiisoftFormModel\Field\ErrorSummary; |
16
|
|
|
use Yiisoft\Form\Field\Fieldset; |
17
|
|
|
use Yiisoft\Form\Field\File; |
18
|
|
|
use Yiisoft\Form\Field\Hidden; |
19
|
|
|
use Yiisoft\Form\Field\Image; |
20
|
|
|
use Yiisoft\Form\Field\Number; |
21
|
|
|
use Yiisoft\Form\Field\Part\Error; |
22
|
|
|
use Yiisoft\Form\Field\Part\Hint; |
23
|
|
|
use Yiisoft\Form\Field\Part\Label; |
24
|
|
|
use Yiisoft\Form\Field\Password; |
25
|
|
|
use Yiisoft\Form\Field\RadioList; |
26
|
|
|
use Yiisoft\Form\Field\Range; |
27
|
|
|
use Yiisoft\Form\Field\ResetButton; |
28
|
|
|
use Yiisoft\Form\Field\Select; |
29
|
|
|
use Yiisoft\Form\Field\SubmitButton; |
30
|
|
|
use Yiisoft\Form\Field\Telephone; |
31
|
|
|
use Yiisoft\Form\Field\Text; |
32
|
|
|
use Yiisoft\Form\Field\Textarea; |
33
|
|
|
use Yiisoft\Form\Field\Url; |
34
|
|
|
|
35
|
|
|
class Field |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string|null |
39
|
|
|
*/ |
40
|
|
|
protected const DEFAULT_THEME = null; |
41
|
|
|
|
42
|
1 |
|
final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button |
43
|
|
|
{ |
44
|
1 |
|
$field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
45
|
|
|
|
46
|
1 |
|
if ($content !== null) { |
47
|
1 |
|
$field = $field->content($content); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
return $field; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
final public static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup |
54
|
|
|
{ |
55
|
1 |
|
return ButtonGroup::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
final public static function checkbox( |
59
|
|
|
FormModelInterface $formModel, |
60
|
|
|
string $attribute, |
61
|
|
|
array $config = [], |
62
|
|
|
?string $theme = null, |
63
|
|
|
): Checkbox { |
64
|
1 |
|
return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
65
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
final public static function checkboxList( |
69
|
|
|
FormModelInterface $formModel, |
70
|
|
|
string $attribute, |
71
|
|
|
array $config = [], |
72
|
|
|
?string $theme = null, |
73
|
|
|
): CheckboxList { |
74
|
1 |
|
return CheckboxList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
75
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
final public static function date( |
79
|
|
|
FormModelInterface $formModel, |
80
|
|
|
string $attribute, |
81
|
|
|
array $config = [], |
82
|
|
|
?string $theme = null, |
83
|
|
|
): Date { |
84
|
1 |
|
return Date::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
85
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
final public static function dateTime( |
89
|
|
|
FormModelInterface $formModel, |
90
|
|
|
string $attribute, |
91
|
|
|
array $config = [], |
92
|
|
|
?string $theme = null, |
93
|
|
|
): DateTime { |
94
|
1 |
|
return DateTime::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
95
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
final public static function dateTimeLocal( |
99
|
|
|
FormModelInterface $formModel, |
100
|
|
|
string $attribute, |
101
|
|
|
array $config = [], |
102
|
|
|
?string $theme = null, |
103
|
|
|
): DateTimeLocal { |
104
|
1 |
|
return DateTimeLocal::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
105
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
final public static function email( |
109
|
|
|
FormModelInterface $formModel, |
110
|
|
|
string $attribute, |
111
|
|
|
array $config = [], |
112
|
|
|
?string $theme = null, |
113
|
|
|
): Email { |
114
|
1 |
|
return Email::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
115
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
116
|
|
|
} |
117
|
|
|
|
118
|
3 |
|
final public static function errorSummary( |
119
|
|
|
FormModelInterface $formModel, |
120
|
|
|
array $config = [], |
121
|
|
|
?string $theme = null, |
122
|
|
|
): ErrorSummary { |
123
|
3 |
|
return ErrorSummary::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
124
|
3 |
|
->validationResult($formModel->getValidationResult()); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
2 |
|
final public static function fieldset(array $config = [], ?string $theme = null): Fieldset |
128
|
|
|
{ |
129
|
2 |
|
return Fieldset::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
1 |
|
final public static function file( |
133
|
|
|
FormModelInterface $formModel, |
134
|
|
|
string $attribute, |
135
|
|
|
array $config = [], |
136
|
|
|
?string $theme = null, |
137
|
|
|
): File { |
138
|
1 |
|
return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
139
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
140
|
|
|
} |
141
|
|
|
|
142
|
2 |
|
final public static function hidden( |
143
|
|
|
FormModelInterface $formModel, |
144
|
|
|
string $attribute, |
145
|
|
|
array $config = [], |
146
|
|
|
?string $theme = null, |
147
|
|
|
): Hidden { |
148
|
2 |
|
return Hidden::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
149
|
2 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
150
|
|
|
} |
151
|
|
|
|
152
|
1 |
|
final public static function image(array $config = [], ?string $theme = null): Image |
153
|
|
|
{ |
154
|
1 |
|
return Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
1 |
|
final public static function number( |
158
|
|
|
FormModelInterface $formModel, |
159
|
|
|
string $attribute, |
160
|
|
|
array $config = [], |
161
|
|
|
?string $theme = null, |
162
|
|
|
): Number { |
163
|
1 |
|
return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
164
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
final public static function password( |
168
|
|
|
FormModelInterface $formModel, |
169
|
|
|
string $attribute, |
170
|
|
|
array $config = [], |
171
|
|
|
?string $theme = null, |
172
|
|
|
): Password { |
173
|
1 |
|
return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
174
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
175
|
|
|
} |
176
|
|
|
|
177
|
1 |
|
final public static function radioList( |
178
|
|
|
FormModelInterface $formModel, |
179
|
|
|
string $attribute, |
180
|
|
|
array $config = [], |
181
|
|
|
?string $theme = null, |
182
|
|
|
): RadioList { |
183
|
1 |
|
return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
184
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
185
|
|
|
} |
186
|
|
|
|
187
|
1 |
|
final public static function range( |
188
|
|
|
FormModelInterface $formModel, |
189
|
|
|
string $attribute, |
190
|
|
|
array $config = [], |
191
|
|
|
?string $theme = null, |
192
|
|
|
): Range { |
193
|
1 |
|
return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
194
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
195
|
|
|
} |
196
|
|
|
|
197
|
1 |
|
final public static function resetButton( |
198
|
|
|
?string $content = null, |
199
|
|
|
array $config = [], |
200
|
|
|
?string $theme = null, |
201
|
|
|
): ResetButton { |
202
|
1 |
|
$field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
203
|
|
|
|
204
|
1 |
|
if ($content !== null) { |
205
|
1 |
|
$field = $field->content($content); |
206
|
|
|
} |
207
|
|
|
|
208
|
1 |
|
return $field; |
209
|
|
|
} |
210
|
|
|
|
211
|
1 |
|
final public static function select( |
212
|
|
|
FormModelInterface $formModel, |
213
|
|
|
string $attribute, |
214
|
|
|
array $config = [], |
215
|
|
|
?string $theme = null, |
216
|
|
|
): Select { |
217
|
1 |
|
return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
218
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
219
|
|
|
} |
220
|
|
|
|
221
|
1 |
|
final public static function submitButton( |
222
|
|
|
?string $content = null, |
223
|
|
|
array $config = [], |
224
|
|
|
?string $theme = null, |
225
|
|
|
): SubmitButton { |
226
|
1 |
|
$field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME); |
227
|
|
|
|
228
|
1 |
|
if ($content !== null) { |
229
|
1 |
|
$field = $field->content($content); |
230
|
|
|
} |
231
|
|
|
|
232
|
1 |
|
return $field; |
233
|
|
|
} |
234
|
|
|
|
235
|
1 |
|
final public static function telephone( |
236
|
|
|
FormModelInterface $formModel, |
237
|
|
|
string $attribute, |
238
|
|
|
array $config = [], |
239
|
|
|
?string $theme = null, |
240
|
|
|
): Telephone { |
241
|
1 |
|
return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
242
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
243
|
|
|
} |
244
|
|
|
|
245
|
3 |
|
final public static function text( |
246
|
|
|
FormModelInterface $formModel, |
247
|
|
|
string $attribute, |
248
|
|
|
array $config = [], |
249
|
|
|
?string $theme = null, |
250
|
|
|
): Text { |
251
|
3 |
|
return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
252
|
3 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
253
|
|
|
} |
254
|
|
|
|
255
|
1 |
|
final public static function textarea( |
256
|
|
|
FormModelInterface $formModel, |
257
|
|
|
string $attribute, |
258
|
|
|
array $config = [], |
259
|
|
|
?string $theme = null, |
260
|
|
|
): Textarea { |
261
|
1 |
|
return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
262
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
263
|
|
|
} |
264
|
|
|
|
265
|
1 |
|
final public static function url( |
266
|
|
|
FormModelInterface $formModel, |
267
|
|
|
string $attribute, |
268
|
|
|
array $config = [], |
269
|
|
|
?string $theme = null, |
270
|
|
|
): Url { |
271
|
1 |
|
return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
272
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
273
|
|
|
} |
274
|
|
|
|
275
|
1 |
|
final public static function label( |
276
|
|
|
FormModelInterface $formModel, |
277
|
|
|
string $attribute, |
278
|
|
|
array $config = [], |
279
|
|
|
?string $theme = null, |
280
|
|
|
): Label { |
281
|
1 |
|
return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
282
|
1 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
283
|
|
|
} |
284
|
|
|
|
285
|
6 |
|
final public static function hint( |
286
|
|
|
FormModelInterface $formModel, |
287
|
|
|
string $attribute, |
288
|
|
|
array $config = [], |
289
|
|
|
?string $theme = null, |
290
|
|
|
): Hint { |
291
|
6 |
|
return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
292
|
6 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
293
|
|
|
} |
294
|
|
|
|
295
|
6 |
|
final public static function error( |
296
|
|
|
FormModelInterface $formModel, |
297
|
|
|
string $attribute, |
298
|
|
|
array $config = [], |
299
|
|
|
?string $theme = null, |
300
|
|
|
): Error { |
301
|
6 |
|
return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME) |
302
|
6 |
|
->inputData(new FormModelInputData($formModel, $attribute)); |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
|