fix: [component:CRUD] Regression where entities not supporting metafields couldn't be saved

pull/93/head
Sami Mokaddem 2021-11-23 14:56:25 +01:00
parent fd21934641
commit 3c0237f387
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 9 additions and 5 deletions

View File

@ -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'];
}
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);