mirror of
https://github.com/flextype/flextype.git
synced 2025-08-16 10:04:21 +02:00
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.
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user