2021-07-26 11:16:52 +02:00
|
|
|
<?php
|
2021-07-30 08:17:00 +02:00
|
|
|
if ($setting['type'] == 'string' || $setting['type'] == 'textarea' || empty($setting['type'])) {
|
2021-07-26 11:16:52 +02:00
|
|
|
$input = (function ($settingName, $setting, $appView) {
|
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-07-30 08:17:00 +02:00
|
|
|
return $appView->Bootstrap->genNode(
|
|
|
|
$setting['type'] == 'textarea' ? 'textarea' : 'input',
|
|
|
|
[
|
|
|
|
'class' => [
|
|
|
|
'form-control',
|
2021-09-17 17:51:45 +02:00
|
|
|
'pe-4',
|
2021-07-30 08:17:00 +02:00
|
|
|
(!empty($setting['error']) ? 'is-invalid' : ''),
|
|
|
|
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
|
|
|
|
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
|
|
|
|
],
|
|
|
|
($setting['type'] == 'textarea' ? '' : 'type') => ($setting['type'] == 'textarea' ? '' : 'text'),
|
|
|
|
'id' => $settingId,
|
|
|
|
'data-setting-name' => $settingName,
|
|
|
|
'value' => isset($setting['value']) ? $setting['value'] : "",
|
|
|
|
'placeholder' => $setting['default'] ?? '',
|
|
|
|
'aria-describedby' => "{$settingId}Help"
|
|
|
|
]
|
|
|
|
);
|
2021-07-26 11:16:52 +02:00
|
|
|
})($settingName, $setting, $this);
|
|
|
|
|
|
|
|
} elseif ($setting['type'] == 'boolean') {
|
|
|
|
$input = (function ($settingName, $setting, $appView) {
|
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
2021-09-18 11:21:50 +02:00
|
|
|
return $this->Bootstrap->switch([
|
|
|
|
'label' => h($setting['description']),
|
|
|
|
'checked' => !empty($setting['value']),
|
|
|
|
'id' => $settingId,
|
2021-07-26 11:16:52 +02:00
|
|
|
'class' => [
|
|
|
|
(!empty($setting['error']) ? 'is-invalid' : ''),
|
2021-07-30 08:17:00 +02:00
|
|
|
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
|
2021-07-26 11:16:52 +02:00
|
|
|
],
|
2021-09-18 11:21:50 +02:00
|
|
|
'attrs' => [
|
|
|
|
'data-setting-name' => $settingName
|
|
|
|
]
|
2021-07-26 11:16:52 +02:00
|
|
|
]);
|
|
|
|
})($settingName, $setting, $this);
|
|
|
|
$description = '';
|
|
|
|
|
|
|
|
} elseif ($setting['type'] == 'integer') {
|
|
|
|
$input = (function ($settingName, $setting, $appView) {
|
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
|
|
|
return $appView->Bootstrap->genNode('input', [
|
|
|
|
'class' => [
|
|
|
|
'form-control',
|
|
|
|
(!empty($setting['error']) ? 'is-invalid' : ''),
|
|
|
|
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
|
|
|
|
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
|
|
|
|
],
|
|
|
|
'type' => 'number',
|
|
|
|
'min' => '0',
|
|
|
|
'step' => 1,
|
|
|
|
'id' => $settingId,
|
|
|
|
'data-setting-name' => $settingName,
|
|
|
|
'aria-describedby' => "{$settingId}Help"
|
|
|
|
]);
|
|
|
|
})($settingName, $setting, $this);
|
|
|
|
|
2021-07-30 14:50:40 +02:00
|
|
|
} elseif ($setting['type'] == 'select' || $setting['type'] == 'multi-select') {
|
2021-07-26 11:16:52 +02:00
|
|
|
$input = (function ($settingName, $setting, $appView) {
|
|
|
|
$settingId = str_replace('.', '_', $settingName);
|
|
|
|
$setting['value'] = $setting['value'] ?? '';
|
2021-10-20 12:21:13 +02:00
|
|
|
if ($setting['type'] == 'multi-select') {
|
2021-10-20 12:48:13 +02:00
|
|
|
if (!is_array($setting['value'])) {
|
|
|
|
$firstChar = substr($setting['value'], 0, 1);
|
|
|
|
if ($firstChar != '{' && $firstChar != '[') { // make sure to cast a simple string into an array
|
|
|
|
$setting['value'] = sprintf('["%s"]', $setting['value']);
|
|
|
|
}
|
|
|
|
$setting['value'] = json_decode($setting['value']);
|
|
|
|
}
|
2021-07-30 14:50:40 +02:00
|
|
|
}
|
2021-10-20 12:21:13 +02:00
|
|
|
$options = [];
|
|
|
|
$options[] = $appView->Bootstrap->genNode('option', ['value' => '-1', 'data-is-empty-option' => '1'], __('Select an option'));
|
2021-07-26 11:16:52 +02:00
|
|
|
foreach ($setting['options'] as $key => $value) {
|
2021-10-20 12:21:13 +02:00
|
|
|
$optionParam = [
|
2021-07-26 11:16:52 +02:00
|
|
|
'class' => [],
|
|
|
|
'value' => $key,
|
2021-10-20 12:21:13 +02:00
|
|
|
];
|
|
|
|
if ($setting['type'] == 'multi-select') {
|
|
|
|
if (in_array($key, $setting['value'])) {
|
|
|
|
$optionParam['selected'] = 'selected';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($setting['value'] == $key) {
|
|
|
|
$optionParam['selected'] = 'selected';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$options[] = $appView->Bootstrap->genNode('option', $optionParam, h($value));
|
2021-07-26 11:16:52 +02:00
|
|
|
}
|
|
|
|
$options = implode('', $options);
|
|
|
|
return $appView->Bootstrap->genNode('select', [
|
|
|
|
'class' => [
|
2021-09-17 17:51:45 +02:00
|
|
|
'form-select',
|
|
|
|
'pe-4',
|
2021-07-26 11:16:52 +02:00
|
|
|
(!empty($setting['error']) ? 'is-invalid' : ''),
|
|
|
|
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
|
|
|
|
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
|
|
|
|
],
|
2021-10-20 12:21:13 +02:00
|
|
|
($setting['type'] == 'multi-select' ? 'multiple' : '') => ($setting['type'] == 'multi-select' ? 'multiple' : ''),
|
2021-07-26 11:16:52 +02:00
|
|
|
'id' => $settingId,
|
|
|
|
'data-setting-name' => $settingName,
|
|
|
|
'placeholder' => $setting['default'] ?? '',
|
|
|
|
'aria-describedby' => "{$settingId}Help"
|
|
|
|
], $options);
|
|
|
|
})($settingName, $setting, $this);
|
|
|
|
}
|
|
|
|
echo $input;
|