From 9953227d901cf3f78ffdaba4a4260ee4796ab7c3 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 14 Mar 2022 17:04:33 -0400 Subject: [PATCH 1/3] comvert afterFetch method to an event handler for model.afterFetch --- modules/cms/models/ThemeData.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 907887d7e8..92608236b5 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -52,6 +52,16 @@ class ThemeData extends Model */ protected static $instances = []; + /** + * Constructor + */ + public function __construct(array $attributes = []) + { + parent::__construct(); + + $this->bindEvent('model.afterFetch', [$this, 'afterFetchHandler']); + } + /** * Before saving the model, strip dynamic attributes applied from config. * @return void @@ -109,7 +119,7 @@ public static function forTheme($theme) * on form field definitions. * @return void */ - public function afterFetch() + protected function afterFetchHandler() { $data = (array) $this->data + $this->getDefaultValues(); From 5e259507ea83001f9825099939c6bb2cae966421 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 14 Mar 2022 18:01:26 -0400 Subject: [PATCH 2/3] use afterBoot() hook instead --- modules/cms/models/ThemeData.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 92608236b5..5680617d35 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -53,12 +53,10 @@ class ThemeData extends Model protected static $instances = []; /** - * Constructor + * after the model is booted, bind to 'model.afterFetch' event */ - public function __construct(array $attributes = []) + public function afterBoot() { - parent::__construct(); - $this->bindEvent('model.afterFetch', [$this, 'afterFetchHandler']); } From c32e8ccb316545883cb77066f34f17df3470fae6 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 14 Mar 2022 18:16:09 -0400 Subject: [PATCH 3/3] move comment to a more appropriate location --- modules/cms/models/ThemeData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 5680617d35..b6ff9af8b4 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -121,14 +121,14 @@ protected function afterFetchHandler() { $data = (array) $this->data + $this->getDefaultValues(); - /* - * Repeater form fields store arrays and must be jsonable. - */ foreach ($this->getFormFields() as $id => $field) { if (!isset($field['type'])) { continue; } + /* + * Repeater form fields store arrays and must be jsonable. + */ if ($field['type'] === 'repeater') { $this->jsonable[] = $id; }