1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PWWEB\Artomator\Utils; |
4
|
|
|
|
5
|
|
|
use InfyOm\Generator\Common\GeneratorField; |
6
|
|
|
use InfyOm\Generator\Utils\GeneratorFieldsInputUtil; |
7
|
|
|
|
8
|
|
|
class VueFieldGenerator |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Generate HTML. |
12
|
|
|
* |
13
|
|
|
* @param GeneratorField $field Field. |
14
|
|
|
* @param string $templateType Template type. |
15
|
|
|
* @param bool $localized Localized. |
16
|
|
|
* |
17
|
|
|
* @return string |
18
|
|
|
*/ |
19
|
|
|
public static function generateHTML(GeneratorField $field, $templateType, $localized = false) |
20
|
|
|
{ |
21
|
|
|
$fieldTemplate = ''; |
22
|
|
|
|
23
|
|
|
$localized = (true === $localized) ? '_locale' : ''; |
24
|
|
|
switch ($field->htmlType) { |
25
|
|
|
case 'text': |
26
|
|
|
case 'textarea': |
27
|
|
|
case 'date': |
28
|
|
|
case 'file': |
29
|
|
|
case 'email': |
30
|
|
|
case 'password': |
31
|
|
|
case 'number': |
32
|
|
|
$fieldTemplate = get_template('scaffold.vues.fields.'.$field->htmlType.$localized, $templateType); |
33
|
|
|
|
34
|
|
|
break; |
35
|
|
|
case 'select': |
36
|
|
|
case 'enum': |
37
|
|
|
$fieldTemplate = get_template('scaffold.vues.fields.select'.$localized, $templateType); |
38
|
|
|
$radioLabels = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues); |
39
|
|
|
|
40
|
|
|
$fieldTemplate = str_replace( |
41
|
|
|
'$INPUT_ARR$', |
42
|
|
|
GeneratorFieldsInputUtil::prepareKeyValueArrayStr($radioLabels), |
43
|
|
|
$fieldTemplate |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
break; |
47
|
|
|
case 'checkbox': |
48
|
|
|
$fieldTemplate = get_template('scaffold.vues.fields.checkbox'.$localized, $templateType); |
49
|
|
|
if (count($field->htmlValues) > 0) { |
50
|
|
|
$checkboxValue = $field->htmlValues[0]; |
51
|
|
|
} else { |
52
|
|
|
$checkboxValue = 1; |
53
|
|
|
} |
54
|
|
|
$fieldTemplate = str_replace('$CHECKBOX_VALUE$', $checkboxValue, $fieldTemplate); |
55
|
|
|
|
56
|
|
|
break; |
57
|
|
|
case 'radio': |
58
|
|
|
$fieldTemplate = get_template('scaffold.vues.fields.radio_group'.$localized, $templateType); |
59
|
|
|
$radioTemplate = get_template('scaffold.vues.fields.radio'.$localized, $templateType); |
60
|
|
|
|
61
|
|
|
$radioLabels = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues); |
62
|
|
|
|
63
|
|
|
$radioButtons = []; |
64
|
|
|
foreach ($radioLabels as $label => $value) { |
65
|
|
|
$radioButtonTemplate = str_replace('$LABEL$', $label, $radioTemplate); |
66
|
|
|
$radioButtonTemplate = str_replace('$VALUE$', $value, $radioButtonTemplate); |
67
|
|
|
$radioButtons[] = $radioButtonTemplate; |
68
|
|
|
} |
69
|
|
|
$fieldTemplate = str_replace('$RADIO_BUTTONS$', implode("\n", $radioButtons), $fieldTemplate); |
70
|
|
|
|
71
|
|
|
break; |
72
|
|
|
case 'toggle-switch': |
73
|
|
|
$fieldTemplate = get_template('scaffold.vues.fields.toggle-switch'.$localized, $templateType); |
74
|
|
|
|
75
|
|
|
break; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $fieldTemplate; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|