2021-12-08 11:11:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Cake\Utility\Inflector;
|
|
|
|
|
|
|
|
$default_template = [
|
|
|
|
'inputContainer' => '<div class="row mb-3 metafield-container">{{content}}</div>',
|
|
|
|
'inputContainerError' => '<div class="row mb-3 metafield-container has-error">{{content}}</div>',
|
|
|
|
'formGroup' => '<label class="col-sm-2 col-form-label form-label" {{attrs}}>{{label}}</label><div class="col-sm-10">{{input}}{{error}}</div>',
|
|
|
|
'error' => '<div class="error-message invalid-feedback d-block">{{content}}</div>',
|
|
|
|
'errorList' => '<ul>{{content}}</ul>',
|
|
|
|
'errorItem' => '<li>{{text}}</li>',
|
|
|
|
];
|
|
|
|
$this->Form->setTemplates($default_template);
|
|
|
|
$backupTemplates = $this->Form->getTemplates();
|
|
|
|
|
|
|
|
$fieldsHtml = '';
|
|
|
|
foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
|
|
|
|
$metaTemplateField->label = Inflector::humanize($metaTemplateField->field);
|
|
|
|
if (!empty($metaTemplateField->metaFields)) {
|
|
|
|
if (!empty($metaTemplateField->multiple)) {
|
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/multiFieldScaffold',
|
|
|
|
[
|
|
|
|
'metaFieldsEntities' => $metaTemplateField->metaFields,
|
|
|
|
'metaTemplateField' => $metaTemplateField,
|
|
|
|
'multiple' => !empty($metaTemplateField->multiple),
|
|
|
|
'form' => $this->Form,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$metaField = reset($metaTemplateField->metaFields);
|
|
|
|
$fieldData = [
|
|
|
|
'label' => $metaTemplateField->label,
|
2022-11-14 09:04:35 +01:00
|
|
|
'type' => $metaTemplateField->formType,
|
2021-12-08 11:11:46 +01:00
|
|
|
];
|
2022-11-14 09:04:35 +01:00
|
|
|
if ($metaTemplateField->formType === 'dropdown') {
|
|
|
|
$fieldData = array_merge_recursive($fieldData, $metaTemplateField->formOptions);
|
|
|
|
}
|
2022-01-20 12:00:39 +01:00
|
|
|
if (isset($metaField->id)) {
|
|
|
|
$fieldData['field'] = sprintf('MetaTemplates.%s.meta_template_fields.%s.metaFields.%s.value', $metaField->meta_template_id, $metaField->meta_template_field_id, $metaField->id);
|
|
|
|
} 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));
|
|
|
|
}
|
2022-11-09 14:00:18 +01:00
|
|
|
if ($metaTemplateField->type === 'boolean') {
|
|
|
|
$fieldData['type'] = 'checkbox';
|
|
|
|
}
|
2021-12-08 11:11:46 +01:00
|
|
|
$this->Form->setTemplates($backupTemplates);
|
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/fieldScaffold',
|
|
|
|
[
|
|
|
|
'fieldData' => $fieldData,
|
|
|
|
'metaTemplateField' => $metaTemplateField,
|
|
|
|
'form' => $this->Form
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!empty($metaTemplateField->multiple)) {
|
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/multiFieldScaffold',
|
|
|
|
[
|
|
|
|
'metaFieldsEntities' => [],
|
|
|
|
'metaTemplateField' => $metaTemplateField,
|
|
|
|
'multiple' => !empty($metaTemplateField->multiple),
|
|
|
|
'form' => $this->Form,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->Form->setTemplates($backupTemplates);
|
|
|
|
$fieldData = [
|
|
|
|
'field' => sprintf('MetaTemplates.%s.meta_template_fields.%s.metaFields.new.0', $metaTemplateField->meta_template_id, $metaTemplateField->id),
|
|
|
|
'label' => $metaTemplateField->label,
|
2022-11-14 09:04:35 +01:00
|
|
|
'type' => $metaTemplateField->formType,
|
2021-12-08 11:11:46 +01:00
|
|
|
];
|
2022-11-14 09:04:35 +01:00
|
|
|
if ($metaTemplateField->formType === 'dropdown') {
|
|
|
|
$fieldData = array_merge_recursive($fieldData, $metaTemplateField->formOptions);
|
|
|
|
}
|
2022-11-14 14:53:02 +01:00
|
|
|
// if ($metaTemplateField->type === 'boolean') {
|
|
|
|
// $fieldData['type'] = 'checkbox';
|
|
|
|
// }
|
2021-12-08 11:11:46 +01:00
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/fieldScaffold',
|
|
|
|
[
|
|
|
|
'fieldData' => $fieldData,
|
|
|
|
'form' => $this->Form
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 09:04:35 +01:00
|
|
|
$fieldContainer = $this->Bootstrap->genNode('div', [
|
|
|
|
'class' => [],
|
|
|
|
], $fieldsHtml);
|
|
|
|
echo $fieldContainer;
|