-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathHandleInertiaRequests.php
More file actions
97 lines (79 loc) · 2.58 KB
/
HandleInertiaRequests.php
File metadata and controls
97 lines (79 loc) · 2.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Statamic\Http\Middleware\CP;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Statamic\CP\Toasts\Manager;
use Statamic\Statamic;
class HandleInertiaRequests extends Middleware
{
protected $rootView = 'statamic::layout';
public function version(Request $request): ?string
{
return parent::version($request);
}
public function __construct(private Manager $toasts)
{
//
}
public function share(Request $request): array
{
return array_filter([
...parent::share($request),
'_statamic' => [
'version' => Statamic::version(),
'cmsName' => __(Statamic::pro() ? config('statamic.cp.custom_cms_name', 'Statamic') : 'Statamic'),
'logos' => $this->logos(),
],
'_toasts' => $this->toasts($request),
]);
}
private function logos()
{
if (! Statamic::pro()) {
return [
'text' => null,
'siteName' => config('app.name'),
'light' => ['nav' => null, 'outside' => null],
'dark' => ['nav' => null, 'outside' => null],
];
}
if (is_string($light = config('statamic.cp.custom_logo_url'))) {
$light = ['nav' => $light, 'outside' => $light];
}
if (is_string($dark = config('statamic.cp.custom_dark_logo_url'))) {
$dark = ['nav' => $dark, 'outside' => $dark];
}
return [
'text' => config('statamic.cp.custom_logo_text'),
'siteName' => config('app.name'),
'light' => [
'nav' => $light['nav'] ?? null,
'outside' => $light['outside'] ?? null,
],
'dark' => [
'nav' => $dark['nav'] ?? null,
'outside' => $dark['outside'] ?? null,
],
];
}
private function toasts(Request $request)
{
$session = $request->session();
if ($message = $session->get('success')) {
$this->toasts->success($message);
}
// Laravel's built-in auth flows (password reset, etc.) flash to 'status'.
if ($message = $session->get('status')) {
$this->toasts->success($message);
}
if ($message = $session->get('error')) {
$this->toasts->error($message);
}
if ($message = $session->get('info')) {
$this->toasts->info($message);
}
$toasts = $this->toasts->toArray();
$this->toasts->clear();
return $toasts;
}
}