From 3c0237f387a14cf02a7bd911b0b499f375702ca6 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 23 Nov 2021 14:56:25 +0100 Subject: [PATCH] fix: [component:CRUD] Regression where entities not supporting metafields couldn't be saved --- src/Controller/Component/CRUDComponent.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index d461edf..cb30abb 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -193,9 +193,11 @@ class CRUDComponent extends Component public function add(array $params = []): void { - $metaTemplates = $this->getMetaTemplates(); $data = $this->Table->newEmptyEntity(); - $data = $this->attachMetaTemplates($data, $metaTemplates->toArray()); + if ($this->metaFieldsSupported()) { + $metaTemplates = $this->getMetaTemplates(); + $data = $this->attachMetaTemplatesIfNeeded($data, $metaTemplates->toArray()); + } if (!empty($params['fields'])) { $this->Controller->set('fields', $params['fields']); } @@ -211,9 +213,11 @@ class CRUDComponent extends Component if (!empty($params['fields'])) { $patchEntityParams['fields'] = $params['fields']; } - $massagedData = $this->massageMetaFields($data, $input, $metaTemplates); - unset($input['MetaTemplates']); // Avoid MetaTemplates to be overriden when patching entity - $data = $massagedData['entity']; + if ($this->metaFieldsSupported()) { + $massagedData = $this->massageMetaFields($data, $input, $metaTemplates); + unset($input['MetaTemplates']); // Avoid MetaTemplates to be overriden when patching entity + $data = $massagedData['entity']; + } $data = $this->Table->patchEntity($data, $input, $patchEntityParams); if (isset($params['beforeSave'])) { $data = $params['beforeSave']($data);