From 8ba7215af85e38a070cbcc0aa7f47ceb89d4e75b Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 21 Feb 2020 13:15:06 +0300 Subject: [PATCH] feat(core): remove complex logic for themes initialization process enabled option should be removed from all themes settings, because only one theme can be enabled for site. --- flextype/core/Themes.php | 56 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/flextype/core/Themes.php b/flextype/core/Themes.php index 7a295de1..cbca4e1d 100644 --- a/flextype/core/Themes.php +++ b/flextype/core/Themes.php @@ -69,19 +69,19 @@ class Themes // Go through the themes list... foreach ($themes_list as $theme) { - // Set site theme directory - $site_theme_settings_dir = PATH['config']['site'] . '/themes/' . $theme['dirname']; + // Set custom theme directory + $custom_theme_settings_dir = PATH['config']['site'] . '/themes/' . $theme['dirname']; // Set default theme settings and manifest files $default_theme_settings_file = PATH['themes'] . '/' . $theme['dirname'] . '/settings.yaml'; $default_theme_manifest_file = PATH['themes'] . '/' . $theme['dirname'] . '/theme.yaml'; - // Set site theme settings and manifest files - $site_theme_settings_file = PATH['config']['site'] . '/themes/' . $theme['dirname'] . '/settings.yaml'; - $site_theme_manifest_file = PATH['config']['site'] . '/themes/' . $theme['dirname'] . '/theme.yaml'; + // Set custom theme settings and manifest files + $custom_theme_settings_file = PATH['config']['site'] . '/themes/' . $theme['dirname'] . '/settings.yaml'; + $custom_theme_manifest_file = PATH['config']['site'] . '/themes/' . $theme['dirname'] . '/theme.yaml'; - // Create site theme settings directory - ! Filesystem::has($site_theme_settings_dir) and Filesystem::createDir($site_theme_settings_dir); + // Create custom theme settings directory + ! Filesystem::has($custom_theme_settings_dir) and Filesystem::createDir($custom_theme_settings_dir); // Check if default theme settings file exists if (! Filesystem::has($default_theme_settings_file)) { @@ -90,17 +90,21 @@ class Themes // Get default theme manifest content $default_theme_settings_file_content = Filesystem::read($default_theme_settings_file); - $default_theme_settings = $this->flextype['parser']->decode($default_theme_settings_file_content, 'yaml'); - - // Create site theme settings file - ! Filesystem::has($site_theme_settings_file) and Filesystem::write($site_theme_settings_file, $default_theme_settings_file_content); - - // Get site theme settings content - $site_theme_settings_file_content = Filesystem::read($site_theme_settings_file); - if (trim($site_theme_settings_file_content) === '') { - $site_theme_settings = []; + if (trim($default_theme_settings_file_content) === '') { + $default_theme_settings = []; } else { - $site_theme_settings = $this->flextype['parser']->decode($site_theme_settings_file_content, 'yaml'); + $default_theme_settings = $this->flextype['parser']->decode($default_theme_settings_file_content, 'yaml'); + } + + // Create custom theme settings file + ! Filesystem::has($custom_theme_settings_file) and Filesystem::write($custom_theme_settings_file, $default_theme_settings_file_content); + + // Get custom theme settings content + $custom_theme_settings_file_content = Filesystem::read($custom_theme_settings_file); + if (trim($custom_theme_settings_file_content) === '') { + $custom_theme_settings = []; + } else { + $custom_theme_settings = $this->flextype['parser']->decode($custom_theme_settings_file_content, 'yaml'); } // Check if default theme manifest file exists @@ -112,21 +116,21 @@ class Themes $default_theme_manifest_file_content = Filesystem::read($default_theme_manifest_file); $default_theme_manifest = $this->flextype['parser']->decode($default_theme_manifest_file_content, 'yaml'); - // Create site theme file - ! Filesystem::has($site_theme_manifest_file) and Filesystem::write($site_theme_manifest_file, $default_theme_manifest_file_content); + // Create custom theme file + ! Filesystem::has($custom_theme_manifest_file) and Filesystem::write($custom_theme_manifest_file, $default_theme_manifest_file_content); - // Get site theme manifest content - $site_theme_manifest_file_content = Filesystem::read($site_theme_manifest_file); - if (trim($site_theme_manifest_file_content) === '') { - $site_theme_manifest = []; + // Get custom theme manifest content + $custom_theme_manifest_file_content = Filesystem::read($custom_theme_manifest_file); + if (trim($custom_theme_manifest_file_content) === '') { + $custom_theme_manifest = []; } else { - $site_theme_manifest = $this->flextype['parser']->decode($site_theme_manifest_file_content, 'yaml'); + $custom_theme_manifest = $this->flextype['parser']->decode($custom_theme_manifest_file_content, 'yaml'); } // Merge theme settings and manifest data $themes[$theme['dirname']] = array_merge( - array_replace_recursive($default_theme_settings, $site_theme_settings), - array_replace_recursive($default_theme_manifest, $site_theme_manifest) + array_replace_recursive($default_theme_settings, $custom_theme_settings), + array_replace_recursive($default_theme_manifest, $custom_theme_manifest) ); }