chg: [metaTemplateField] More generic way to specify form type

pull/121/head
Sami Mokaddem 2022-11-14 15:45:28 +01:00
parent b6fdf37d54
commit 84069cfe40
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 4 additions and 8 deletions

View File

@ -14,6 +14,8 @@ class MetaTemplateField extends AppModel
$formType = 'text';
if (!empty($this->sane_default) || !empty($this->values_list)) {
$formType = 'dropdown';
} else if ($this->type === 'boolean') {
$formType = 'checkbox';
}
return $formType;
}

View File

@ -33,7 +33,7 @@ foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
'label' => $metaTemplateField->label,
'type' => $metaTemplateField->formType,
];
if ($metaTemplateField->formType === 'dropdown') {
if (!empty($metaTemplateField->formOptions)) {
$fieldData = array_merge_recursive($fieldData, $metaTemplateField->formOptions);
}
if (isset($metaField->id)) {
@ -41,9 +41,6 @@ foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
} else {
$fieldData['field'] = sprintf('MetaTemplates.%s.meta_template_fields.%s.metaFields.%s.value', $metaField->meta_template_id, $metaField->meta_template_field_id, array_key_first($metaTemplateField->metaFields));
}
if ($metaTemplateField->type === 'boolean') {
$fieldData['type'] = 'checkbox';
}
$this->Form->setTemplates($backupTemplates);
$fieldsHtml .= $this->element(
'genericElements/Form/fieldScaffold',
@ -72,12 +69,9 @@ foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
'label' => $metaTemplateField->label,
'type' => $metaTemplateField->formType,
];
if ($metaTemplateField->formType === 'dropdown') {
if (!empty($metaTemplateField->formOptions)) {
$fieldData = array_merge_recursive($fieldData, $metaTemplateField->formOptions);
}
// if ($metaTemplateField->type === 'boolean') {
// $fieldData['type'] = 'checkbox';
// }
$fieldsHtml .= $this->element(
'genericElements/Form/fieldScaffold',
[