forked from inetis-ch/oc-richeditorsnippets-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.php
31 lines (24 loc) · 960 Bytes
/
routes.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
<?php
use Cms\Classes\Theme;
use RainLab\Pages\Classes\SnippetManager;
Route::get('/inetis/snippets/list', function () {
$user = BackendAuth::getUser();
if (!$user || !$user->hasAccess('rainlab.pages.access_snippets')) {
return response('Forbidden', 401);
}
$snippetManager = SnippetManager::instance();
$theme = Theme::getActiveTheme();
$snippets = $snippetManager->listSnippets($theme);
// Transform to a collection, set the data we need and orgnaise with array keys.
$snippets = collect($snippets)
->transform(function ($item, $key) {
return [
'component' => $item->getComponentClass(),
'snippet' => $item->code,
'name' => $item->getName(),
];
})
->keyBy('snippet');
return response('$.oc.snippets = ' . $snippets, 200)
->header('Content-Type', 'application/javascript');
})->middleware('web');