Brand settings can now be seeded from config

This commit is contained in:
Samuel Georges 2016-08-13 07:56:11 +10:00
parent 42a702f70a
commit 6353ded91f
3 changed files with 41 additions and 16 deletions

View File

@ -2,7 +2,7 @@
use Backend\Models\BrandSetting;
use Backend\Models\EditorSetting;
?>
<?php if (BrandSetting::isConfigured()): ?>
<?php if (BrandSetting::isConfigured() || BrandSetting::isBaseConfigured()): ?>
<style>
<?= BrandSetting::renderCss() ?>
</style>

View File

@ -1,9 +1,12 @@
<?php namespace Backend\Models;
use App;
use Url;
use File;
use Lang;
use Model;
use Cache;
use Config;
use Less_Parser;
use Exception;
@ -48,14 +51,14 @@ class BrandSetting extends Model
public function initSettingsData()
{
$this->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;
}
}

View File

@ -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()
{