forked from junohamburg/kirby-visual-block-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
34 lines (28 loc) · 947 Bytes
/
index.php
File metadata and controls
34 lines (28 loc) · 947 Bytes
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
<?php
use Kirby\Cms\App as Kirby;
use Composer\Semver\Semver;
// Validate Kirby version
if (Semver::satisfies(Kirby::version() ?? '0.0.0', '~5.0') === false) {
throw new Exception('The visual block selector plugin requires Kirby 5');
}
Kirby::plugin('junohamburg/visual-block-selector', [
'api' => [
'routes' => [
[
'pattern' => 'visual-block-selector',
'action' => function () {
$previewImages = [];
$dir = 'block-previews';
$path = kirby()->root('assets') . '/' . $dir;
$imageFiles = Dir::files($path);
$relativePath = str_replace(kirby()->root('index') . '/', '', kirby()->root('assets'));
foreach ($imageFiles as $image) {
$imageAsset = asset($relativePath . '/' . $dir . '/' . $image);
$previewImages[$imageAsset->name()] = $imageAsset->url();
}
return $previewImages;
}
]
]
]
]);