2020-12-07 09:52:35 +01:00
|
|
|
<?php
|
2021-11-03 11:47:10 +01:00
|
|
|
|
2020-12-07 09:52:35 +01:00
|
|
|
use Cake\Utility\Inflector;
|
|
|
|
|
2021-11-03 11:47:10 +01:00
|
|
|
$default_template = [
|
|
|
|
'inputContainer' => '<div class="row mb-3 metafield-container">{{content}}</div>',
|
|
|
|
'inputContainerError' => '<div class="row mb-3 metafield-container has-error">{{content}}</div>',
|
2021-11-04 10:47:03 +01:00
|
|
|
'formGroup' => '<label class="col-sm-2 col-form-label form-label" {{attrs}}>{{label}}</label><div class="col-sm-10">{{input}}{{error}}</div>',
|
2021-11-03 11:47:10 +01:00
|
|
|
];
|
|
|
|
$this->Form->setTemplates($default_template);
|
|
|
|
$backupTemplates = $this->Form->getTemplates();
|
2020-12-07 09:52:35 +01:00
|
|
|
$tabData = [];
|
2021-11-08 14:08:47 +01:00
|
|
|
foreach ($entity->MetaTemplates as $i => $metaTemplate) {
|
2020-12-10 17:46:16 +01:00
|
|
|
if ($metaTemplate->is_default) {
|
|
|
|
$tabData['navs'][$i] = [
|
|
|
|
'html' => $this->element('/genericElements/MetaTemplates/metaTemplateNav', ['metaTemplate' => $metaTemplate])
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$tabData['navs'][$i] = [
|
|
|
|
'text' => $metaTemplate->name
|
|
|
|
];
|
|
|
|
}
|
2020-12-07 09:52:35 +01:00
|
|
|
$fieldsHtml = '';
|
2021-11-03 11:47:10 +01:00
|
|
|
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 = [
|
|
|
|
'field' => sprintf('MetaTemplates.%s.meta_template_fields.%s.metaFields.%s.value', $metaField->meta_template_id, $metaField->meta_template_field_id, $metaField->id),
|
2021-11-04 10:47:03 +01:00
|
|
|
'label' => $metaTemplateField->label,
|
2021-11-03 11:47:10 +01:00
|
|
|
];
|
2021-11-04 10:47:03 +01:00
|
|
|
$this->Form->setTemplates($backupTemplates);
|
2021-11-03 11:47:10 +01:00
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/fieldScaffold',
|
|
|
|
[
|
|
|
|
'fieldData' => $fieldData,
|
|
|
|
'metaTemplateField' => $metaTemplateField,
|
|
|
|
'form' => $this->Form
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-04 08:10:32 +01:00
|
|
|
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),
|
2021-11-04 10:47:03 +01:00
|
|
|
'label' => $metaTemplateField->label,
|
2021-11-04 08:10:32 +01:00
|
|
|
];
|
|
|
|
$fieldsHtml .= $this->element(
|
|
|
|
'genericElements/Form/fieldScaffold',
|
|
|
|
[
|
|
|
|
'fieldData' => $fieldData,
|
|
|
|
'form' => $this->Form
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2021-11-03 11:47:10 +01:00
|
|
|
}
|
2020-12-07 09:52:35 +01:00
|
|
|
}
|
|
|
|
$tabData['content'][$i] = $fieldsHtml;
|
|
|
|
}
|
2021-11-04 10:47:03 +01:00
|
|
|
$this->Form->setTemplates($backupTemplates);
|
2020-12-07 09:52:35 +01:00
|
|
|
echo $this->Bootstrap->Tabs([
|
|
|
|
'pills' => true,
|
|
|
|
'data' => $tabData,
|
2021-11-04 15:19:45 +01:00
|
|
|
'nav-class' => ['shadow mb-3 p-2 rounded'],
|
|
|
|
'content-class' => ['pt-2 px-3']
|
2021-11-03 11:47:10 +01:00
|
|
|
]);
|