chg: [CRUD component] internal changes

- removed saveMetaFields function from the component
- fixed issues with associations being patched in automatically for add/edit
pull/38/head
iglocska 2021-01-13 14:18:26 +01:00
parent 7e4580e50a
commit 7159034e9e
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 10 additions and 17 deletions

View File

@ -75,7 +75,12 @@ class CRUDComponent extends Component
$this->Controller->set('fields', $params['fields']);
}
if ($this->request->is('post')) {
$patchEntityParams = [];
$patchEntityParams = [
'associated' => []
];
if (!empty($params['id'])) {
unset($params['id']);
}
$input = $this->__massageInput($params);
if (!empty($params['fields'])) {
$patchEntityParams['fields'] = $params['fields'];
@ -136,21 +141,7 @@ class CRUDComponent extends Component
private function saveMetaFields($id, $input)
{
foreach ($input['metaFields'] as $metaField => $values) {
if (!is_array($values)) {
$values = [$values];
}
foreach ($values as $value) {
if ($value !== '') {
$temp = $this->MetaFields->newEmptyEntity();
$temp->field = $metaField;
$temp->value = $value;
$temp->scope = $this->Table->metaFields;
$temp->parent_id = $id;
$this->MetaFields->save($temp);
}
}
}
$this->Table->saveMetaFields($id, $input);
}
private function __massageInput($params)
@ -182,7 +173,9 @@ class CRUDComponent extends Component
$this->Controller->set('fields', $params['fields']);
}
if ($this->request->is(['post', 'put'])) {
$patchEntityParams = [];
$patchEntityParams = [
'associated' => []
];
$input = $this->__massageInput($params);
if (!empty($params['fields'])) {
$patchEntityParams['fields'] = $params['fields'];