-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLanguageSwitch.php
More file actions
55 lines (44 loc) · 1.64 KB
/
Copy pathLanguageSwitch.php
File metadata and controls
55 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Statikbe\FilamentFlexibleContentBlockPages\Components;
use Illuminate\Support\Facades\Route;
use Illuminate\View\Component;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
use Statikbe\FilamentFlexibleContentBlockPages\FilamentFlexibleContentBlockPagesServiceProvider;
use Statikbe\FilamentFlexibleContentBlockPages\Models\Page;
class LanguageSwitch extends Component
{
public ?Page $page;
public function __construct()
{
$this->page = $this->getPage();
}
public function render()
{
$theme = FilamentFlexibleContentBlockPages::config()->getTheme();
$package = FilamentFlexibleContentBlockPagesServiceProvider::PACKAGE_PREFIX;
$template = "{$package}::{$theme}.components.language-switch";
// Check if the themed template exists, otherwise fallback to tailwind theme
if (view()->exists($template)) {
return view($template);
}
// Final fallback to tailwind theme
/** @var view-string $fallbackTemplate */
$fallbackTemplate = "{$package}::tailwind.components.language-switch";
return view($fallbackTemplate);
}
public function shouldRender(): bool
{
return count(LaravelLocalization::getSupportedLocales()) > 1;
}
protected function getPage(): Page
{
$page = Route::current()->parameter('page');
if (! $page) {
if (Route::current()->getName() === 'home') {
$page = Page::getByCode(Page::HOME_PAGE);
}
}
return $page;
}
}