Skip to content

Commit 70a972a

Browse files
committed
language switch as registered component
1 parent 3e44085 commit 70a972a

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
@if(count(LaravelLocalization::getSupportedLocales()) > 1)
2-
@php
3-
use \Illuminate\Support\Facades\Route;
1+
@php
2+
use Illuminate\Support\Facades\Route;
43
5-
$page = Route::current()->parameter('page');
6-
@endphp
4+
$page = Route::current()->parameter('page');
5+
@endphp
76

8-
<nav class="relative inline-block text-right">
9-
<div class="py-1 flex" role="none">
10-
@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
11-
<a href="{{$page && is_object($page) ? $page->getViewUrl($localeCode) : '#'}}"
12-
class="text-gray-700 block px-4 py-2 text-sm"
13-
role="menuitem"
14-
id="menu-item-{{$localeCode}}">
15-
{{ $properties['native'] }}
16-
</a>
17-
@endforeach
18-
</div>
19-
</nav>
20-
@endif
7+
<nav class="relative inline-block text-right">
8+
<div class="py-1 flex" role="none">
9+
@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
10+
<a href="{{$page && is_object($page) ? $page->getViewUrl($localeCode) : '#'}}"
11+
class="text-gray-700 block px-4 py-2 text-sm"
12+
role="menuitem"
13+
id="menu-item-{{$localeCode}}">
14+
{{ $properties['native'] }}
15+
</a>
16+
@endforeach
17+
</div>
18+
</nav>

resources/views/pages/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<x-layouts.base title="{{ $page->title }}" wide="true">
99
<header>
10-
<x-language-switch/>
10+
<x-flexible-pages-language-switch/>
1111
</header>
1212

1313
<main class="prose-headings:font-base">

src/Commands/SeedDefaultsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle(): void
3939
public function seedHomePage(): void
4040
{
4141
$pageModel = FilamentFlexibleContentBlockPages::config()->getPageModel();
42-
if(!$pageModel::code(Page::HOME_PAGE)->exists()) {
42+
if (! $pageModel::code(Page::HOME_PAGE)->exists()) {
4343
$locales = FilamentFlexibleContentBlockPages::config()->getSupportedLocales();
4444

4545
$homePage = new $pageModel;
@@ -52,7 +52,7 @@ public function seedHomePage(): void
5252
public function seedSettings(): void
5353
{
5454
$settingsModel = FilamentFlexibleContentBlockPages::config()->getSettingsModel();
55-
if($settingsModel::query()->count() === 0) {
55+
if ($settingsModel::query()->count() === 0) {
5656
$locales = FilamentFlexibleContentBlockPages::config()->getSupportedLocales();
5757
$settings = new $settingsModel;
5858

src/FilamentFlexibleContentBlockPagesServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Spatie\LaravelPackageTools\Package;
66
use Spatie\LaravelPackageTools\PackageServiceProvider;
77
use Statikbe\FilamentFlexibleContentBlockPages\Commands\SeedDefaultsCommand;
8+
use Statikbe\FilamentFlexibleContentBlockPages\View\Components\LanguageSwitch;
89

910
class FilamentFlexibleContentBlockPagesServiceProvider extends PackageServiceProvider
1011
{
@@ -25,6 +26,9 @@ public function configurePackage(Package $package): void
2526
'create_filament_flexible_content_block_pages_settings_table',
2627
])
2728
->hasTranslations()
28-
->hasCommand(SeedDefaultsCommand::class);
29+
->hasCommand(SeedDefaultsCommand::class)
30+
->hasViewComponents('flexible-pages',
31+
LanguageSwitch::class,
32+
);
2933
}
3034
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Statikbe\FilamentFlexibleContentBlockPages\View\Components;
4+
5+
use Illuminate\View\Component;
6+
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
7+
8+
class LanguageSwitch extends Component
9+
{
10+
public function render()
11+
{
12+
return view('filament-flexible-content-block-pages::components.language-switch');
13+
}
14+
15+
public function shouldRender(): bool
16+
{
17+
return count(LaravelLocalization::getSupportedLocales()) > 1;
18+
}
19+
}

0 commit comments

Comments
 (0)