From 52fef41f3ce149a2b970b2ea62cec1738d78c66c Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 8 Dec 2020 10:31:17 +0100 Subject: [PATCH] fix: [Component:CRUD] Allow edit of meta-fields and added group_by clause --- src/Controller/Component/CRUDComponent.php | 3 ++- .../element/genericElements/Form/metaTemplateScaffold.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index d00b909..8064a58 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -247,6 +247,7 @@ class CRUDComponent extends Component $query->innerJoinWith('MetaTemplateFields', function ($q) { return $q->contain('MetaFields')->innerJoinWith('MetaFields'); }); + $query->group(['MetaTemplates.id']); $metaTemplates = $query->all(); $data['metaTemplates'] = $metaTemplates; return $data; @@ -262,7 +263,7 @@ class CRUDComponent extends Component $metaFields = $query->all(); $data['metaFields'] = []; foreach($metaFields as $metaField) { - $data['metaFields'][$metaField->field] = $metaField->value; + $data['metaFields'][$metaField->meta_template_id][$metaField->field] = $metaField->value; } return $data; } diff --git a/templates/element/genericElements/Form/metaTemplateScaffold.php b/templates/element/genericElements/Form/metaTemplateScaffold.php index cf32d35..55f6223 100644 --- a/templates/element/genericElements/Form/metaTemplateScaffold.php +++ b/templates/element/genericElements/Form/metaTemplateScaffold.php @@ -9,7 +9,7 @@ foreach($metaTemplatesData as $i => $metaTemplate) { $fieldsHtml = ''; foreach ($metaTemplate->meta_template_fields as $metaField) { $metaField->label = Inflector::humanize($metaField->field); - $metaField->field = sprintf('%s.%s.%s', 'metaFields', $metaTemplate->id, $metaField->field); + $metaField->field = sprintf('%s.%s.%s', 'metaFields', $metaField->meta_template_id, $metaField->field); $fieldsHtml .= $this->element( 'genericElements/Form/fieldScaffold', [ 'fieldData' => $metaField->toArray(),