-
Notifications
You must be signed in to change notification settings - Fork 1
/
chassis.php
executable file
·146 lines (128 loc) · 4.59 KB
/
chassis.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Grav\Theme;
use Grav\Common\Grav;
use Grav\Common\Theme;
use Grav\Theme\Chassis\Utils;
class Chassis extends Theme
{
public static function getSubscribedEvents()
{
return [
'onThemeInitialized' => ['onThemeInitialized', 0],
'onTwigLoader' => ['onTwigLoader', 0],
'onTwigInitialized' => ['onTwigInitialized', 0],
'onAdminPageTypes' => ['onAdminPageTypes', 0],
'onAdminModularPageTypes' => ['onAdminModularPageTypes', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
];
}
public function onThemeInitialized()
{
if ($this->isAdmin()) {
$this->enable([
'onAssetsInitialized' => ['onAdminAssetsInitialized', 0],
]);
}
}
// Add images to twig template paths to allow inclusion of SVG files
public function onTwigLoader()
{
$theme_paths = Grav::instance()['locator']->findResources('theme://dist/img');
foreach($theme_paths as $images_path) {
$this->grav['twig']->addPath($images_path, 'images');
}
$theme_paths = Grav::instance()['locator']->findResources('theme://dist/icons');
foreach($theme_paths as $images_path) {
$this->grav['twig']->addPath($images_path, 'icons');
}
}
public function onTwigInitialized()
{
$twig = $this->grav['twig'];
$form_class_variables = [
// 'form_outer_classes' => 'form-horizontal',
'form_button_outer_classes' => 'form__buttons',
'form_button_classes' => 'button',
'form_errors_classes' => '',
'form_field_outer_classes' => 'form__field',
'form_field_outer_label_classes' => 'form-label-wrapper',
'form_field_label_classes' => 'form__label',
// 'form_field_outer_data_classes' => 'col-9',
'form_field_input_classes' => '',
'form_field_text_classes' => 'text-input',
'form_field_textarea_classes' => 'text-input',
'form_field_select_classes' => 'text-input dropdown',
'form_field_radio_classes' => 'form__radio radio',
'form_field_checkbox_classes' => 'form__checkbox checkbox',
];
$twig->twig_vars = array_merge($twig->twig_vars, $form_class_variables);
}
/*
Define Custom Names for Modular Templates
*/
public function onAdminModularPageTypes( $event )
{
$names = [
'modular/tab-content' => 'Tab Content',
'modular/tabs' => 'Tabs Container',
];
// merge arrays
$list = array_replace( $event['types'], $names );
// drop these that are currently not detected by grav
$list = array_intersect_key( $list, $event['types'] );
// remove unwanted
// unset( $list['modular/default'] );
// sort
asort( $list );
$event['types'] = $list;
}
/*
Define Custom Names for Page Templates
*/
public function onAdminPageTypes( $event )
{
$names = [
'default' => 'Standard-Seite',
'modular' => 'Modulbasierte Seite',
];
// merge arrays
$list = array_replace( $event['types'], $names );
// drop these that are currently not detected by grav
$list = array_intersect_key( $list, $event['types'] );
// remove unwanted
unset( $list['robots'] );
// sort
asort( $list );
$event['types'] = $list;
}
/**
* [onAdminAssetsInitialized]
*
* @return void
*/
public function onAdminAssetsInitialized()
{
$assets = $this->grav['assets'];
// $page = $this->grav['admin']->page();
// if( $page->isPage() ) {}
// admin & editor styles
$assets->addCss( 'theme://dist/css/admin.css' );
// editor buttons
if ($this->config->get('plugins.markdown-notices.enabled')) {
$assets->add( 'theme://admin/buttons/notice.js', [ 'defer' => true ] );
}
if ($this->config->get('plugins.shortcode-core.enabled')) {
$assets->add( 'theme://admin/buttons/shortcodes.js', [ 'defer' => true ] );
}
}
public function onTwigSiteVariables()
{
require_once __DIR__ . '/classes/Utils.php';
$this->grav['twig']->twig_vars['chassis'] = new Utils();
}
public function onShortcodeHandlers()
{
$this->grav['shortcode']->registerAllShortcodes('theme://shortcodes');
}
}