-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathroutes.php
30 lines (24 loc) · 908 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
<?php
use RainLab\Pages\Classes\SnippetManager;
use Cms\Classes\Theme;
Route::get('/toughdeveloper/snippets/list.js', function()
{
$user = BackendAuth::getUser();
if (!BackendAuth::getUser() || !BackendAuth::getUser()->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 '$.oc.snippets = ' . $snippets;
});