From 4ec3b525e04b5b0968a8b971e0364ab010dffaad Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Thu, 6 Sep 2018 17:08:05 +1000 Subject: [PATCH] Fixes event implementation The array_merge approach will only shallow merge the arrays preventing a second event from contributing form fields properly. Passing by reference is the logical thing to do here. --- modules/cms/classes/Theme.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index da5c5d9f4..31470a606 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -323,21 +323,13 @@ class Theme * * Example usage: * - * Event::listen('cms.theme.extendConfig', function ($themeCode, $config) { + * Event::listen('cms.theme.extendConfig', function ($themeCode, &$config) { * $config['name'] = 'October Theme'; * $config['description'] = 'Another great theme from October CMS'; - * return $config; * }); * */ - if ($results = Event::fire('cms.theme.extendConfig', [$this->getDirName(), $config])) { - foreach ($results as $result) { - if (!is_array($result)) { - continue; - } - $config = array_merge($config, $result); - } - } + Event::fire('cms.theme.extendConfig', [$this->getDirName(), &$config]); return $this->configCache = $config; } @@ -361,7 +353,7 @@ class Theme * * Example usage: * - * Event::listen('cms.theme.extendFormConfig', function ($themeCode, $config) { + * Event::listen('cms.theme.extendFormConfig', function ($themeCode, &$config) { * array_set($config, 'tabs.fields.header_color', [ * 'label' => 'Header Colour', * 'type' => 'colorpicker', @@ -369,18 +361,10 @@ class Theme * 'assetVar' => 'header-bg', * 'tab' => 'Global' * ]); - * return $config; * }); * */ - if ($results = Event::fire('cms.theme.extendFormConfig', [$this->getDirName(), $config])) { - foreach ($results as $result) { - if (!is_array($result)) { - continue; - } - $config = array_merge($config, $result); - } - } + Event::fire('cms.theme.extendFormConfig', [$this->getDirName(), &$config]); return $config; }