fix: [Component:CRUD] Pass expected argument

pull/93/head
Sami Mokaddem 2021-11-11 14:51:51 +01:00
parent 6579482526
commit b51cf2ed59
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 6 additions and 4 deletions

View File

@ -396,8 +396,10 @@ class CRUDComponent extends Component
} }
} }
$data = $this->Table->get($id, $getParam); $data = $this->Table->get($id, $getParam);
$metaTemplates = $this->getMetaTemplates(); if ($this->metaFieldsSupported()) {
$data = $this->attachMetaTemplatesIfNeeded($data, $metaTemplates); $metaTemplates = $this->getMetaTemplates();
$data = $this->attachMetaTemplatesIfNeeded($data, $metaTemplates->toArray());
}
if (!empty($params['fields'])) { if (!empty($params['fields'])) {
$this->Controller->set('fields', $params['fields']); $this->Controller->set('fields', $params['fields']);
} }
@ -595,11 +597,11 @@ class CRUDComponent extends Component
return $data; return $data;
} }
if (!is_null($metaTemplates)) { 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 // We deep copy the meta-template so that the data attached is not preserved for the next iteration
$metaTemplates = array_map(function ($metaTemplate) { $metaTemplates = array_map(function ($metaTemplate) {
$tmpEntity = $this->MetaTemplates->newEntity($metaTemplate->toArray()); $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; return $tmpEntity;
}, $metaTemplates); }, $metaTemplates);
} else { } else {