From e49be7b2c6379638c61258e08c285d68a52b7069 Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Thu, 17 Jul 2014 09:55:11 +1000 Subject: [PATCH] Fix jsonable settingsmodel saving --- modules/system/behaviors/SettingsModel.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/system/behaviors/SettingsModel.php b/modules/system/behaviors/SettingsModel.php index bae66482d..669d636a5 100644 --- a/modules/system/behaviors/SettingsModel.php +++ b/modules/system/behaviors/SettingsModel.php @@ -55,6 +55,7 @@ class SettingsModel extends ModelBehavior $this->model->bindEvent('model.afterFetch', [$this, 'afterModelFetch']); $this->model->bindEvent('model.beforeSave', [$this, 'beforeModelSave']); $this->model->bindEvent('model.setAttribute', [$this, 'setModelAttribute']); + $this->model->bindEvent('model.saveInternal', [$this, 'saveModelInternal']); /* * Parse the config @@ -139,15 +140,22 @@ class SettingsModel extends ModelBehavior $this->model->attributes = array_merge($this->fieldValues, $this->model->attributes); } + /** + * Internal save method for the model + * @return void + */ + public function saveModelInternal() + { + // Purge the field values from the attributes + $this->model->attributes = array_diff_key($this->model->attributes, $this->fieldValues); + } + /** * Before the model is saved, ensure the record code is set * and the jsonable field values */ public function beforeModelSave() { - // Purge the field values from the attributes - $this->model->attributes = array_diff_key($this->model->attributes, $this->fieldValues); - $this->model->item = $this->recordCode; if ($this->fieldValues) $this->model->value = $this->fieldValues; @@ -192,4 +200,4 @@ class SettingsModel extends ModelBehavior { return $this->fieldConfig; } -} \ No newline at end of file +}