-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPageController.php
77 lines (62 loc) · 2.18 KB
/
PageController.php
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
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Statamic\Entries\Collection;
use Statamic\Facades\Data;
use Statamic\Facades\Site;
use Statamic\Fields\Value;
use Statamic\Http\Controllers\FrontendController;
use Statamic\Statamic;
use Statamic\Support\Str;
class PageController extends FrontendController {
public function index(Request $request) {
$url = Site::current()->relativePath(
str_finish($request->getUri(), '/')
);
if ($url === '') {
$url = '/';
}
if (Statamic::isAmpRequest()) {
$url = str_after($url, '/' . config('statamic.amp.route'));
}
if (Str::contains($url, '?')) {
$url = substr($url, 0, strpos($url, '?'));
}
## BEGIN EDIT
$routeName = ltrim(str_replace('/', '.', $url), '.') ?: 'home';
$pageName = collect(explode('.', $routeName))->map(function ($segment) {
return Str::studly($segment);
})->join('/');
$cms = new \stdClass;
$layoutName = null;
$templateName = null;
if ($data = Data::findByUri($url, Site::current()->handle())) {
$cms = $data->toAugmentedArray();
if (isset($cms['collection']) && $cms['collection'] instanceof Collection) {
$collection = $cms['collection']->toArray();
if (isset($collection['layout'])) {
$layoutName = Str::studly($collection['layout']);
}
}
if (isset($cms['template']) && $cms['template'] instanceof Value) {
$templateName = Str::studly($cms['template']->raw());
}
}
// if (isset($cms['parent'])) {
// $cms['parent'] = $cms['parent']->toAugmentedArray();
// }
unset($cms['parent']);
return Inertia::render($pageName, [
'cms' => $cms,
])->withViewData([
'statamic' => [
'cms' => $cms,
'pageName' => $pageName,
'layoutName' => $layoutName,
'templateName' => $templateName,
],
]);
## END EDIT ##
}
}