From b51cf2ed5941d7efc17fc0609c66c7df0728ecee Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Thu, 11 Nov 2021 14:51:51 +0100 Subject: [PATCH] fix: [Component:CRUD] Pass expected argument --- src/Controller/Component/CRUDComponent.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 2c1a95a..9a9320f 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -396,8 +396,10 @@ class CRUDComponent extends Component } } $data = $this->Table->get($id, $getParam); - $metaTemplates = $this->getMetaTemplates(); - $data = $this->attachMetaTemplatesIfNeeded($data, $metaTemplates); + if ($this->metaFieldsSupported()) { + $metaTemplates = $this->getMetaTemplates(); + $data = $this->attachMetaTemplatesIfNeeded($data, $metaTemplates->toArray()); + } if (!empty($params['fields'])) { $this->Controller->set('fields', $params['fields']); } @@ -595,11 +597,11 @@ class CRUDComponent extends Component return $data; } if (!is_null($metaTemplates)) { - // We night be in the case where $metaTemplates gets re-used in a while loop + // We might be in the case where $metaTemplates gets re-used in a while loop // We deep copy the meta-template so that the data attached is not preserved for the next iteration $metaTemplates = array_map(function ($metaTemplate) { $tmpEntity = $this->MetaTemplates->newEntity($metaTemplate->toArray()); - $tmpEntity['meta_template_fields'] = Hash::combine($tmpEntity['meta_template_fields'], '{n}.id', '{n}'); // newEntity resets array indexing + $tmpEntity['meta_template_fields'] = Hash::combine($tmpEntity['meta_template_fields'], '{n}.id', '{n}'); // newEntity resets array indexing, see https://github.com/cakephp/cakephp/blob/32e3c532fea8abe2db8b697f07dfddf4dfc134ca/src/ORM/Marshaller.php#L369 return $tmpEntity; }, $metaTemplates); } else {