Skip to content

Commit

Permalink
Fix custom logo when using arrays with null (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Mar 22, 2021
1 parent 7a74fc4 commit 4f6ada5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions resources/views/partials/global-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<button class="nav-toggle md:hidden ml-sm flex-shrink-0" @click="toggleMobileNav" v-else v-cloak aria-label="{{ __('Toggle Mobile Nav') }}">@cp_svg('close')</button>
<a href="{{ route('statamic.cp.index') }}" class="flex items-end">
<div v-tooltip="version" class="hidden md:block flex-shrink-0">
@if (Statamic::pro() && config('statamic.cp.custom_logo_url'))
<img src="{{ config('statamic.cp.custom_logo_url.nav') ?? config('statamic.cp.custom_logo_url') }}" alt="{{ config('statamic.cp.custom_cms_name') }}" class="white-label-logo">
@if ($customLogo)
<img src="{{ $customLogo }}" alt="{{ config('statamic.cp.custom_cms_name') }}" class="white-label-logo">
@else
@cp_svg('statamic-wordmark')
@if (Statamic::pro())<span class="font-bold text-4xs align-top">PRO</span>@endif
Expand Down
4 changes: 2 additions & 2 deletions resources/views/partials/outside-logo.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="logo pt-7">
@if (Statamic::pro() && config('statamic.cp.custom_logo_url'))
<img src="{{ config('statamic.cp.custom_logo_url.outside') ?? config('statamic.cp.custom_logo_url') }}" alt="{{ config('statamic.cp.custom_cms_name') }}" class="white-label-logo">
@if ($customLogo)
<img src="{{ $customLogo }}" alt="{{ config('statamic.cp.custom_cms_name') }}" class="white-label-logo">
@else
@cp_svg('statamic-wordmark')
@endif
Expand Down
50 changes: 50 additions & 0 deletions src/Http/View/Composers/CustomLogoComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Statamic\Http\View\Composers;

use Illuminate\View\View;
use Statamic\Statamic;
use Statamic\Support\Arr;

class CustomLogoComposer
{
const VIEWS = [
'statamic::partials.global-header',
'statamic::partials.outside-logo',
];

public function compose(View $view)
{
$view->with('customLogo', $this->customLogo($view));
}

protected function customLogo($view)
{
if (! Statamic::pro()) {
return false;
}

$config = config('statamic.cp.custom_logo_url');

switch ($view->name()) {
case 'statamic::partials.outside-logo':
$type = 'outside';
break;
case 'statamic::partials.global-header':
$type = 'nav';
break;
default:
$type = 'other';
}

if ($logo = Arr::get($config, $type)) {
return $logo;
}

if (! is_array($config)) {
return $config;
}

return false;
}
}
2 changes: 2 additions & 0 deletions src/Providers/CpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Statamic\Extensions\Translation\Loader;
use Statamic\Extensions\Translation\Translator;
use Statamic\Facades\User;
use Statamic\Http\View\Composers\CustomLogoComposer;
use Statamic\Http\View\Composers\FieldComposer;
use Statamic\Http\View\Composers\JavascriptComposer;
use Statamic\Http\View\Composers\NavComposer;
Expand All @@ -30,6 +31,7 @@ public function boot()
View::composer(SessionExpiryComposer::VIEWS, SessionExpiryComposer::class);
View::composer(JavascriptComposer::VIEWS, JavascriptComposer::class);
View::composer(NavComposer::VIEWS, NavComposer::class);
View::composer(CustomLogoComposer::VIEWS, CustomLogoComposer::class);

CoreUtilities::boot();

Expand Down

0 comments on commit 4f6ada5

Please sign in to comment.