| @@ -16,8 +16,31 @@ | ||
| 16 | 16 | static::$_emailTemplateModel = new EmailTemplateModel(); |
| 17 | 17 | $this->_user_details = $user_details; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** | |
| 21 | + * Decode a stored template `config` column into the object shape the admin editor expects. | |
| 22 | + * | |
| 23 | + * Older versions could persist an empty config as `[]`; decoded, that reaches the React editor | |
| 24 | + * as a JS array and setting a key on it throws inside the immutable-draft library. Anything that | |
| 25 | + * is not a non-empty object collapses to `{}`. | |
| 26 | + * | |
| 27 | + * @param mixed $config raw column value (JSON string, already-decoded value, or null) | |
| 28 | + * | |
| 29 | + * @return object | |
| 30 | + */ | |
| 31 | + public static function normalizeConfig($config) | |
| 32 | + { | |
| 33 | + if (is_string($config)) { | |
| 34 | + $config = json_decode($config); | |
| 35 | + } | |
| 36 | + if (is_array($config)) { | |
| 37 | + $config = (object) $config; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return is_object($config) ? $config : (object) []; | |
| 41 | + } | |
| 42 | + | |
| 20 | 43 | public function getAllTemplate($templateID = null, $userID = null) |
| 21 | 44 | { |
| 22 | 45 | $condition = [ |
| 23 | 46 | 'form_id' => static::$_formID, |