fix: [element] Made single views aware of multiple meta-fields

pull/93/head
Sami Mokaddem 2021-11-05 17:03:11 +01:00
parent bb9ca6e69d
commit 26859d045e
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 17 additions and 12 deletions

View File

@ -334,7 +334,7 @@ class CRUDComponent extends Component
$this->setAllTags();
}
$getParam = isset($params['get']) ? $params['get'] : $params;
if (true) { // TODO: check if has meta field behavior
if ($this->Table->hasBehavior('MetaFields')) {
if (empty($getParam['contain'])) {
$getParam['contain'] = [];
}
@ -500,7 +500,7 @@ class CRUDComponent extends Component
$params['contain'][] = 'Tags';
$this->setAllTags();
}
if ($this->Table->hasBehavior('MetaFields')) { // TODO: check if has meta field behavior
if ($this->Table->hasBehavior('MetaFields')) {
if (!empty($this->request->getQuery('full'))) {
$params['contain']['MetaFields'] = ['MetaTemplateFields' => 'MetaTemplates'];
} else {
@ -509,7 +509,9 @@ class CRUDComponent extends Component
}
$data = $this->Table->get($id, $params);
$data = $this->attachMetaData($id, $data);
$metaTemplates = $this->getMetaTemplates();
$data = $this->attachMetaTemplates($data, $metaTemplates->toArray());
// $data = $this->attachMetaData($id, $data);
if (isset($params['afterFind'])) {
$data = $params['afterFind']($data);
}

View File

@ -1,9 +1,9 @@
<?php
<?php
$tabData = [
'navs' => [],
'content' => []
];
foreach($data['metaTemplates'] as $metaTemplate) {
foreach($data['MetaTemplates'] as $metaTemplate) {
if (!empty($metaTemplate->meta_template_fields)) {
if ($metaTemplate->is_default) {
$tabData['navs'][] = [
@ -16,11 +16,14 @@ foreach($data['metaTemplates'] as $metaTemplate) {
}
$fields = [];
foreach ($metaTemplate->meta_template_fields as $metaTemplateField) {
$metaField = $metaTemplateField->meta_fields[0];
$fields[] = [
'key' => $metaField->field,
'raw' => $metaField->value
];
$labelPrintedOnce = false;
foreach ($metaTemplateField->metaFields as $metaField) {
$fields[] = [
'key' => !$labelPrintedOnce ? $metaField->field : '',
'raw' => $metaField->value
];
$labelPrintedOnce = true;
}
}
$listTable = $this->Bootstrap->listTable([
'hover' => false,

View File

@ -36,7 +36,7 @@
'tableClass' => 'col-sm-8',
'elementsRootPath' => '/genericElements/SingleViews/Fields/'
];
if (!empty($data['metaTemplates']) && (empty($skip_meta_templates)) && !empty($combinedFieldsView)) {
if (!empty($data['MetaTemplates']) && (empty($skip_meta_templates)) && !empty($combinedFieldsView)) {
$listTableOptions['tableClass'] = '';
}
$listTable = $this->Bootstrap->listTable($listTableOptions,[
@ -45,7 +45,7 @@
]);
$metafieldsPanel = '';
if (!empty($data['metaTemplates']) && (empty($skip_meta_templates))) {
if (!empty($data['MetaTemplates']) && (empty($skip_meta_templates))) {
$metaFieldsData = [
'data' => $data,
];