/
forms.twig
494 lines (345 loc) · 14.7 KB
/
forms.twig
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
{% macro errorList(errors) %}
{% include "_includes/forms/errorList" %}
{% endmacro %}
{# Inputs #}
{% macro button(config) %}
{% include '_includes/forms/button' with config only %}
{% endmacro %}
{% macro submitButton(config) %}
{{ _self.button(config|merge({
type: 'submit',
class: (config.class ?? [])|explodeClass|merge(['submit']),
label: config.label ?? 'Submit'|t('app'),
})) }}
{% endmacro %}
{# Inputs #}
{% macro hidden(config) -%}
{% include "_includes/forms/hidden" with config only %}
{%- endmacro %}
{% macro text(config) %}
{% include "_includes/forms/text" with config only %}
{% endmacro %}
{% macro password(config) %}
{% include "_includes/forms/password" with config only %}
{% endmacro %}
{% macro copytext(config) %}
{% include "_includes/forms/copytext" with config only %}
{% endmacro %}
{% macro date(config) %}
{% include "_includes/forms/date" with config only %}
{% endmacro %}
{% macro time(config) %}
{% include "_includes/forms/time" with config only %}
{% endmacro %}
{% macro color(config) %}
{% include "_includes/forms/color" with config only %}
{% endmacro %}
{% macro colorSelect(config) %}
{% include "_includes/forms/colorSelect" with config only %}
{% endmacro %}
{% macro textarea(config) %}
{% include "_includes/forms/textarea" with config only %}
{% endmacro %}
{% macro select(config) %}
{% include "_includes/forms/select" with config only %}
{% endmacro %}
{% macro customSelect(config) %}
{% include "_includes/forms/customSelect" with config only %}
{% endmacro %}
{% macro selectize(config) %}
{% include "_includes/forms/selectize" with config only %}
{% endmacro %}
{% macro multiselect(config) %}
{% include "_includes/forms/multiselect" with config only %}
{% endmacro %}
{% macro checkbox(config) %}
{% include "_includes/forms/checkbox" with config only %}
{% endmacro %}
{% macro checkboxGroup(config) %}
{% include "_includes/forms/checkboxGroup" with config only %}
{% endmacro %}
{% macro checkboxSelect(config) %}
{% include "_includes/forms/checkboxSelect" with config only %}
{% endmacro %}
{% macro radio(config) %}
{% include "_includes/forms/radio" with config only %}
{% endmacro %}
{% macro radioGroup(config) %}
{% include "_includes/forms/radioGroup" with config only %}
{% endmacro %}
{% macro file(config) %}
{% include "_includes/forms/file" with config only %}
{% endmacro %}
{% macro lightswitch(config) %}
{% include "_includes/forms/lightswitch" with config only %}
{% endmacro %}
{% macro editableTable(config) %}
{% include "_includes/forms/editableTable" with config only %}
{% endmacro %}
{% macro elementSelect(config) %}
{% include "_includes/forms/elementSelect" with config only %}
{% endmacro %}
{% macro componentSelect(config) %}
{% include "_includes/forms/componentSelect" with config only %}
{% endmacro %}
{% macro entryTypeSelect(config) %}
{% include "_includes/forms/entryTypeSelect" with config only %}
{% endmacro %}
{% macro autosuggest(config) %}
{% include "_includes/forms/autosuggest" with config only %}
{% endmacro %}
{% macro timeZone(config) %}
{% include "_includes/forms/timeZone" with config only %}
{% endmacro %}
{% macro iconPicker(config) %}
{% include '_includes/forms/iconPicker' with config only %}
{% endmacro %}
{% macro fs(config) %}
{% include "_includes/forms/fs" with config only %}
{% endmacro %}
{% macro volume(config) %}
{% include "_includes/forms/volume" with config only %}
{% endmacro %}
{% macro booleanMenu(config) %}
{% include "_includes/forms/booleanMenu" with config only %}
{% endmacro %}
{% macro languageMenu(config) %}
{% include "_includes/forms/languageMenu" with config only %}
{% endmacro %}
{% macro fieldLayoutDesigner(config) %}
{% include "_includes/forms/fieldLayoutDesigner" with config only %}
{% endmacro %}
{% macro money(config) %}
{% include "_includes/forms/money" with config only %}
{% endmacro %}
{# Fields #}
{% macro field(config, input) %}
{{ craft.cp.field(input ?? '', config)|raw }}
{% endmacro %}
{% macro textField(config) %}
{% set config = config|merge({id: config.id ?? "text#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/text') }}
{% endmacro %}
{% macro copytextField(config) %}
{% set config = config|merge({id: config.id ?? "copytext#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/copytext') }}
{% endmacro %}
{% macro passwordField(config) %}
{% set config = config|merge({id: config.id ?? "password#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/password') }}
{% endmacro %}
{% macro dateField(config) %}
{% set config = config|merge({id: config.id ?? "date#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/date') }}
{% endmacro %}
{% macro timeField(config) %}
{% set config = config|merge({id: config.id ?? "time#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/time') }}
{% endmacro %}
{% macro colorField(config) %}
{% set config = config|merge({
fieldset: true,
id: config.id ?? "color#{random()}"
}) %}
{{ _self.field(config, 'template:_includes/forms/color') }}
{% endmacro %}
{% macro colorSelectField(config) %}
{% set config = config|merge({id: config.id ?? "colorselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/colorSelect') }}
{% endmacro %}
{% macro dateTimeField(config) %}
{% set config = config|merge({
id: config.id ?? "datetime#{random()}",
fieldset: true,
}) %}
{{ _self.field(config, 'template:_includes/forms/datetime') }}
{% endmacro %}
{% macro textareaField(config) %}
{% set config = config|merge({id: config.id ?? "textarea#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/textarea') }}
{% endmacro %}
{% macro selectField(config) %}
{% set config = config|merge({id: config.id ?? "select#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/select') }}
{% endmacro %}
{% macro customSelectField(config) %}
{% set config = config|merge({id: config.id ?? "customselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/customSelect') }}
{% endmacro %}
{% macro selectizeField(config) %}
{% set config = config|merge({id: config.id ?? "selectize#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: (config.allowedEnvValues is not defined)
? 'This can be set to an environment variable matching one of the option values.'|t('app')
: 'This can be set to an environment variable.'|t('app'),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/selectize') }}
{% endmacro %}
{% macro multiselectField(config) %}
{% set config = config|merge({id: config.id ?? "multiselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/multiselect') }}
{% endmacro %}
{% macro checkboxField(config) %}
{# label --> checkboxLabel #}
{% set config = config|merge({
fieldset: config.fieldLabel is defined,
fieldClass: (config.fieldClass ?? [])|explodeClass|push('checkboxfield'),
id: config.id ?? "checkbox#{random()}",
checkboxLabel: config.label ?? null,
instructionsPosition: config.instructionsPosition ?? 'after',
})|withoutKey('label') %}
{{ _self.field(config, 'template:_includes/forms/checkbox') }}
{% endmacro %}
{% macro checkboxGroupField(config) %}
{% set config = config|merge({
fieldset: true,
id: config.id ?? "checkboxgroup#{random()}",
}) %}
{{ _self.field(config, 'template:_includes/forms/checkboxGroup') }}
{% endmacro %}
{% macro checkboxSelectField(config) %}
{% set config = config|merge({
fieldset: true,
id: config.id ?? "checkboxselect#{random()}",
}) %}
{{ _self.field(config, 'template:_includes/forms/checkboxSelect') }}
{% endmacro %}
{% macro radioGroupField(config) %}
{% set config = config|merge({
fieldset: true,
id: config.id ?? "radiogroup#{random()}",
}) %}
{{ _self.field(config, 'template:_includes/forms/radioGroup') }}
{% endmacro %}
{% macro fileField(config) %}
{% set config = config|merge({id: config.id ?? "file#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/file') }}
{% endmacro %}
{% macro lightswitchField(config) %}
{% set config = config|merge({
id: config.id ?? "lightswitch#{random()}",
fieldClass: (config.fieldClass ?? [])|explodeClass|push('lightswitch-field'),
fieldLabel: config.fieldLabel ?? config.label ?? null,
})|withoutKey('label') %}
{{ _self.field(config, 'template:_includes/forms/lightswitch') }}
{% endmacro %}
{% macro editableTableField(config) %}
{% set config = config|merge({id: config.id ?? "editabletable#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/editableTable') }}
{% endmacro %}
{% macro elementSelectField(config) %}
{% set config = config|merge({id: config.id ?? "elementselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/elementSelect') }}
{% endmacro %}
{% macro componentSelectField(config) %}
{% set config = config|merge({id: config.id ?? "componentselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/componentSelect') }}
{% endmacro %}
{% macro entryTypeSelectField(config) %}
{% set config = config|merge({id: config.id ?? "entrytypeselect#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/entryTypeSelect') }}
{% endmacro %}
{% macro autosuggestField(config) %}
{% set config = config|merge({
id: config.id ?? "autosuggest#{random()}",
}) %}
{# Suggest an environment variable / alias? #}
{% if (config.suggestEnvVars ?? false) %}
{% set value = config.value ?? '' %}
{% if config.tip is not defined and value[0:1] not in ['$', '@'] %}
{% set config = config|merge({
tip: ((config.suggestAliases ?? false)
? 'This can be set to an environment variable, or begin with an alias.'|t('app')
: 'This can be set to an environment variable.'|t('app')) ~ ' ' ~ tag('a', {
href: 'https://craftcms.com/docs/4.x/config/#control-panel-settings',
class: 'go',
text: 'Learn more'|t('app'),
}),
}) %}
{% elseif config.warning is not defined and (value == '@web' or value[0:5] == '@web/') and craft.app.request.isWebAliasSetDynamically %}
{% set config = config|merge({
warning: 'The `@web` alias is not recommended if it is determined automatically.'|t('app')
}) %}
{% endif %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/autosuggest') }}
{% endmacro %}
{% macro timeZoneField(config) %}
{% set config = config|merge({id: config.id ?? "timezone#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: 'This can be set to an environment variable with a value of a [supported time zone]({url}).'|t('app', {
url: 'https://www.php.net/manual/en/timezones.php',
}),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/timeZone') }}
{% endmacro %}
{% macro iconPickerField(config) %}
{% set config = config|merge({id: config.id ?? "iconpicker#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/iconPicker') }}
{% endmacro %}
{% macro fsField(config) %}
{% set config = config|merge({id: config.id ?? "fs#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: 'This can be set to an environment variable matching one of the option values.'|t('app'),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/fs') }}
{% endmacro %}
{% macro volumeField(config) %}
{% set config = config|merge({id: config.id ?? "volume#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: 'This can be set to an environment variable matching one of the option values.'|t('app'),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/volume') }}
{% endmacro %}
{% macro booleanMenuField(config) %}
{% set config = config|merge({id: config.id ?? "booleanmenu#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: 'This can be set to an environment variable with a boolean value ({examples}).'|t('app', {
examples: '`yes`/`no`/`true`/`false`/`on`/`off`/`0`/`1`',
}),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/booleanMenu') }}
{% endmacro %}
{% macro languageMenuField(config) %}
{% set config = config|merge({id: config.id ?? "languagemenu#{random()}"}) %}
{% if (config.includeEnvVars ?? false) and config.tip is not defined and (config.value ?? '')[0:1] != '$' %}
{% set config = config|merge({
tip: 'This can be set to an environment variable with a valid language ID ({examples}).'|t('app', {
examples: '`en`/`en-GB`',
}),
}) %}
{% endif %}
{{ _self.field(config, 'template:_includes/forms/languageMenu') }}
{% endmacro %}
{% macro fieldLayoutDesignerField(config) %}
{{ _self.field({
label: 'Field Layout'|t('app'),
errors: (config.fieldLayout ?? false) ? config.fieldLayout.getErrorSummary(true),
}|merge(config), 'template:_includes/forms/fieldLayoutDesigner') }}
{% endmacro %}
{% macro moneyField(config) %}
{% set config = config|merge({id: config.id ?? "money#{random()}"}) %}
{{ _self.field(config, 'template:_includes/forms/money') }}
{% endmacro %}
{# Other #}
{% macro optionShortcutLabel(key, shift, alt) -%}
<span class="shortcut">{{ _self.shortcutText(key, shift, alt) }}</span>
{%- endmacro %}
{% macro shortcutText(key, shift, alt) %}
{%- switch craft.app.request.getClientOs() %}
{%- case 'Mac' %}
{{- (alt ? '⌥') ~ (shift ? '⇧') ~ '⌘' ~ key }}
{%- default %}
{{- 'Ctrl+' ~ (alt ? 'Alt+') ~ (shift ? 'Shift+') ~ key }}
{%- endswitch %}
{%- endmacro %}