Added favicon management to back-end customisation (#4045)

Credit to @Farrow. Also accessible with `brand.faviconPath` configuration item.
This commit is contained in:
Farrow 2019-01-22 05:25:56 +00:00 committed by Luke Towers
parent 920eb15af5
commit 1caaac9704
5 changed files with 38 additions and 2 deletions

View File

@ -427,6 +427,8 @@ return [
'brand' => 'Brand',
'logo' => 'Logo',
'logo_description' => 'Upload a custom logo to use in the back-end.',
'favicon' => 'Favicon',
'favicon_description' => 'Upload a custom favicon to use in the back-end',
'app_name' => 'App Name',
'app_name_description' => 'This name is shown in the title area of the back-end.',
'app_tagline' => 'App Tagline',

View File

@ -7,7 +7,7 @@
<meta name="backend-timezone" content="<?= e(Backend\Models\Preference::get('timezone')) ?>">
<meta name="backend-locale" content="<?= e(Backend\Models\Preference::get('locale')) ?>">
<meta name="csrf-token" content="<?= csrf_token() ?>">
<link rel="icon" type="image/png" href="<?= Backend::skinAsset('assets/images/favicon.png') ?>">
<link rel="icon" type="image/png" href="<?= e(Backend\Models\BrandSetting::getFavicon()) ?>">
<title data-title-template="<?= empty($this->pageTitleTemplate) ? '%s' : e($this->pageTitleTemplate) ?> | <?= e(Backend\Models\BrandSetting::get('app_name')) ?>">
<?= e(trans($this->pageTitle)) ?> | <?= e(Backend\Models\BrandSetting::get('app_name')) ?>
</title>

View File

@ -7,7 +7,7 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="backend-base-path" content="<?= Backend::baseUrl() ?>">
<meta name="csrf-token" content="<?= csrf_token() ?>">
<link rel="icon" type="image/png" href="<?= Backend::skinAsset('assets/images/favicon.png') ?>">
<link rel="icon" type="image/png" href="<?= e(Backend\Models\BrandSetting::getFavicon()) ?>">
<title><?= e(trans('backend::lang.auth.title')) ?></title>
<link href="<?= Url::asset('modules/system/assets/ui/storm.css') ?>" rel="stylesheet">
<link href="<?= Url::to('modules/backend/assets/css/october.css') ?>" rel="stylesheet">

View File

@ -1,6 +1,7 @@
<?php namespace Backend\Models;
use App;
use Backend;
use Url;
use File;
use Lang;
@ -39,6 +40,7 @@ class BrandSetting extends Model
public $settingsFields = 'fields.yaml';
public $attachOne = [
'favicon' => \System\Models\File::class,
'logo' => \System\Models\File::class
];
@ -85,6 +87,17 @@ class BrandSetting extends Model
Cache::forget(self::instance()->cacheKey);
}
public static function getFavicon()
{
$settings = self::instance();
if ($settings->favicon) {
return $settings->favicon->getPath();
}
return self::getDefaultFavicon() ?: null;
}
public static function getLogo()
{
$settings = self::instance();
@ -147,6 +160,17 @@ class BrandSetting extends Model
return !!Config::get('brand');
}
public static function getDefaultFavicon()
{
$faviconPath = File::symbolizePath(Config::get('brand.faviconPath'));
if ($faviconPath && File::exists($faviconPath)) {
return Url::asset(File::localToPublic($faviconPath));
}
return Backend::skinAsset('assets/images/favicon.png');
}
public static function getDefaultLogo()
{
$logoPath = File::symbolizePath(Config::get('brand.logoPath'));

View File

@ -29,6 +29,16 @@ tabs:
tab: backend::lang.branding.brand
span: left
favicon:
label: backend::lang.branding.favicon
type: fileupload
commentAbove: backend::lang.branding.favicon_description
mode: image
imageHeight: 32
tab: backend::lang.branding.brand
span: right
fileTypes: jpg,jpeg,bmp,png,webp,gif,svg,ico
primary_color:
label: backend::lang.branding.primary_color
type: colorpicker