From 84069cfe4074e2ef268a2da3320a80015ab1fb00 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 14 Nov 2022 15:45:28 +0100 Subject: [PATCH] chg: [metaTemplateField] More generic way to specify form type --- src/Model/Entity/MetaTemplateField.php | 2 ++ .../element/genericElements/Form/metaTemplateForm.php | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Model/Entity/MetaTemplateField.php b/src/Model/Entity/MetaTemplateField.php index 110f843..1a355d8 100644 --- a/src/Model/Entity/MetaTemplateField.php +++ b/src/Model/Entity/MetaTemplateField.php @@ -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; } diff --git a/templates/element/genericElements/Form/metaTemplateForm.php b/templates/element/genericElements/Form/metaTemplateForm.php index c09982d..f52cbb2 100644 --- a/templates/element/genericElements/Form/metaTemplateForm.php +++ b/templates/element/genericElements/Form/metaTemplateForm.php @@ -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', [