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