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