From 6353ded91fd7482d954b9c2c1cacce9fb64a942c Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 13 Aug 2016 07:56:11 +1000 Subject: [PATCH] Brand settings can now be seeded from config --- modules/backend/layouts/_custom_styles.htm | 2 +- modules/backend/models/BrandSetting.php | 54 ++++++++++++++++------ modules/system/behaviors/SettingsModel.php | 1 + 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/modules/backend/layouts/_custom_styles.htm b/modules/backend/layouts/_custom_styles.htm index f6f8e564e..8eec0413b 100644 --- a/modules/backend/layouts/_custom_styles.htm +++ b/modules/backend/layouts/_custom_styles.htm @@ -2,7 +2,7 @@ use Backend\Models\BrandSetting; use Backend\Models\EditorSetting; ?> - + diff --git a/modules/backend/models/BrandSetting.php b/modules/backend/models/BrandSetting.php index 718ecc880..253d537a1 100644 --- a/modules/backend/models/BrandSetting.php +++ b/modules/backend/models/BrandSetting.php @@ -1,9 +1,12 @@ app_name = Lang::get('system::lang.app.name'); - $this->app_tagline = Lang::get('system::lang.app.tagline'); + $config = App::make('config'); - $this->primary_color = self::PRIMARY_COLOR; - $this->secondary_color = self::SECONDARY_COLOR; - $this->accent_color = self::ACCENT_COLOR; - - $this->menu_mode = self::INLINE_MENU; + $this->app_name = $config->get('brand.appName', Lang::get('system::lang.app.name')); + $this->app_tagline = $config->get('brand.tagline', Lang::get('system::lang.app.tagline')); + $this->primary_color = $config->get('brand.primaryColor', self::PRIMARY_COLOR); + $this->secondary_color = $config->get('brand.secondaryColor', self::SECONDARY_COLOR); + $this->accent_color = $config->get('brand.accentColor', self::ACCENT_COLOR); + $this->menu_mode = $config->get('brand.menuMode', self::INLINE_MENU); } public function afterSave() @@ -66,11 +69,12 @@ class BrandSetting extends Model public static function getLogo() { $settings = self::instance(); - if (!$settings->logo) { - return null; + + if ($settings->logo) { + return $settings->logo->getPath(); } - return $settings->logo->getPath(); + return self::getDefaultLogo() ?: null; } public static function renderCss() @@ -93,22 +97,21 @@ class BrandSetting extends Model public static function compileCss() { $parser = new Less_Parser(['compress' => true]); + $basePath = base_path('modules/backend/models/brandsetting'); $primaryColor = self::get('primary_color', self::PRIMARY_COLOR); $secondaryColor = self::get('secondary_color', self::PRIMARY_COLOR); $accentColor = self::get('accent_color', self::ACCENT_COLOR); - $vars = [ + $parser->ModifyVars([ 'logo-image' => "'".self::getLogo()."'", 'brand-primary' => $primaryColor, 'brand-secondary' => $secondaryColor, 'brand-accent' => $accentColor, - ]; - - $parser->ModifyVars($vars); + ]); $parser->parse( - File::get(base_path().'/modules/backend/models/brandsetting/custom.less') . + File::get($basePath . '/custom.less') . self::get('custom_css') ); @@ -116,4 +119,25 @@ class BrandSetting extends Model return $css; } + + // + // Base line configuration + // + + public static function isBaseConfigured() + { + return !!Config::get('brand'); + } + + public static function getDefaultLogo() + { + $logoPath = File::symbolizePath(Config::get('brand.logoPath')); + + if ($logoPath && File::exists($logoPath)) { + return Url::asset(File::localToPublic($logoPath)); + } + + return null; + } + } diff --git a/modules/system/behaviors/SettingsModel.php b/modules/system/behaviors/SettingsModel.php index 9790f7ff3..54b35a110 100644 --- a/modules/system/behaviors/SettingsModel.php +++ b/modules/system/behaviors/SettingsModel.php @@ -100,6 +100,7 @@ class SettingsModel extends ModelBehavior /** * Checks if the model has been set up previously, intended as a static method + * @return bool */ public function isConfigured() {