From 46cacf5e3f262f2b9f6e661dbe9d735df9a7376f Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 24 Jan 2017 20:31:58 -0800 Subject: [PATCH] Fix for custom fields loading in edit mode. --- e107_admin/cpage.php | 19 ++++++++++++++++--- e107_handlers/e_customfields_class.php | 12 ++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index 53c2d5fac..c95b4f133 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -729,7 +729,7 @@ class page_admin_ui extends e_admin_ui if(!empty($row['chapter_fields'])) { - $this->chapterFields[$cat] = e107::unserialize($row['chapter_fields']); + $this->chapterFields[$cat] = ($row['chapter_fields']); } @@ -799,7 +799,7 @@ class page_admin_ui extends e_admin_ui if(!empty($this->chapterFields[$chap])) { - e107::getCustomFields()->loadConfig($this->chapterFields[$chap])->setTab($tabId, "Additional")->setAdminUIConfig('page_fields',$this); + e107::getCustomFields()->setTab($tabId, "Additional")->loadConfig($this->chapterFields[$chap])->setAdminUIConfig('page_fields',$this); } else { @@ -807,6 +807,19 @@ class page_admin_ui extends e_admin_ui } } + private function loadCustomFieldsData() + { + $row = e107::getDb()->retrieve('page', 'page_chapter, page_fields', 'page_id='.$this->getId()); + + $cf = e107::getCustomFields(); + + $cf->loadData($row['page_fields'])->setAdminUIData('page_fields',$this); + + // e107::getDebug()->log($cf); + + + } + function CreateObserver() { @@ -827,7 +840,7 @@ class page_admin_ui extends e_admin_ui $chap = intval($row['page_chapter']); $this->initCustomFields($chap); - e107::getCustomFields()->loadData($row['page_fields'])->setAdminUIData('page_fields',$this); + $this->loadCustomFieldsData(); } diff --git a/e107_handlers/e_customfields_class.php b/e107_handlers/e_customfields_class.php index ea967553b..bed4e1fd9 100644 --- a/e107_handlers/e_customfields_class.php +++ b/e107_handlers/e_customfields_class.php @@ -311,10 +311,11 @@ $ui->addTab($tabKey, $this->_tab[$tabKey]); - foreach($this->_config as $key=>$fld) + foreach($this->_config as $k=>$fld) { $fld['tab'] = $tabKey; $fld['data'] = false; + $key = $fld['key']; if($fld['type'] === 'icon') { @@ -333,8 +334,6 @@ $fields[$fieldName.'__'.$key] = $fld; - //$model->fields[$fieldName.'__'.$key] = $fld; - } $ui->setFieldAttr($fields); @@ -352,21 +351,18 @@ */ public function setAdminUIData($fieldname, e_admin_ui &$ui) { - // $model->getModel()->set($fieldname, null); - - // e107::getCustomFields()->setData($row['page_fields']); $ui->getModel()->set($fieldname, null); foreach($this->_data as $key=>$value) { $ui->getModel()->set($fieldname.'__'.$key, $value); + // e107::getDebug()->log($fieldname.'__'.$key.": ".$value); } return $this; - } @@ -424,7 +420,7 @@ unset($new_data[$fieldname]); // Reset. $len = strlen($fieldname); - + foreach($new_data as $k=>$v) { if(substr($k,0,$len) === $fieldname)