Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.1] Fix custom logo when using arrays with null #3408

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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