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.
This commit is contained in:
Samuel Georges 2018-09-06 17:08:05 +10:00
parent 8f82a89147
commit 4ec3b525e0
1 changed files with 4 additions and 20 deletions

View File

@ -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;
}