From 0b74734fae701be469ca830acb7b5aba4ec4ffd3 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 22 Mar 2016 20:03:00 +1100 Subject: [PATCH] Make room to load theme options from files For example: form: path/to/fields.yaml --- modules/cms/classes/Theme.php | 17 +++++++++++++++++ modules/cms/controllers/Themes.php | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 05e15ecde..7f84c4d7d 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -302,6 +302,23 @@ class Theme return array_get($this->getConfig(), $name, $default); } + /** + * Returns an array value from the theme configuration file by its name. + * If the value is a string, it is treated as a YAML file and loaded. + * @param string $name Specifies the configuration parameter name. + * @return array + */ + public function getConfigArray($name) + { + $result = array_get($this->getConfig(), $name, []); + + if (is_string($result)) { + // Load from file + } + + return (array) $result; + } + /** * Writes to the theme.yaml file with the supplied array values. * @param array $values Data to write diff --git a/modules/cms/controllers/Themes.php b/modules/cms/controllers/Themes.php index 64a6db77e..8848fbcee 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -251,16 +251,17 @@ class Themes extends Controller { $model = $form->model; $theme = $this->findThemeObject($model->theme); + $config = $theme->getConfigArray('form'); - if ($fields = $theme->getConfigValue('form.fields')) { + if ($fields = array_get($config, 'fields')) { $form->addFields($fields); } - if ($fields = $theme->getConfigValue('form.tabs.fields')) { + if ($fields = array_get($config, 'tabs.fields')) { $form->addTabFields($fields); } - if ($fields = $theme->getConfigValue('form.secondaryTabs.fields')) { + if ($fields = array_get($config, 'secondaryTabs.fields')) { $form->addSecondaryTabFields($fields); } }