forked from medienbaecker/kirby-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·57 lines (53 loc) · 1.73 KB
/
index.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
<?php
use Kirby\Cms\Template;
include __DIR__ . '/lib/models.php';
include __DIR__ . '/lib/functions.php';
include __DIR__ . '/lib/collection.php';
$moduleRegistry = createModuleRegistry();
Kirby::plugin('medienbaecker/modules', [
'templates' => $moduleRegistry['templates'],
'pageModels' => $moduleRegistry['pageModels'],
'blueprints' => $moduleRegistry['blueprints'],
'sections' => [
'modules' => include __DIR__ . '/lib/sections/modules.php'
],
'fields' => [
'modules_redirect' => include __DIR__ . '/lib/fields/redirect.php'
],
'pageMethods' => [
'renderModules' => function () {
foreach ($this->modules() as $module) {
$moduleTemplate = new Template($module->intendedTemplate());
echo $moduleTemplate->render([
'page' => $this,
'module' => $module,
'site' => $this->site()
]);
}
},
'hasModules' => function () {
$modules = array_filter($this->blueprint()->sections(), function ($section) {
return 'modules' === $section->type();
});
return count($modules) > 0;
},
'modules' => function () {
$modules = new ModulesCollection;
if ($rawModules = $this->find('modules')) {
foreach ($rawModules->childrenAndDrafts() as $module) {
if (!$module->isListed() && !$module->isDraft()) continue;
if ($module->isDraft && !$module->isVerified(get('token'))) continue;
$modules->append($module);
}
}
return $modules;
},
'isModule' => function () {
return Str::startsWith($this->intendedTemplate(), 'module.');
}
],
'api' => [
'routes' => include __DIR__ . '/lib/routes.php',
],
'translations' => include __DIR__ . '/lib/translations.php',
]);