-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcustom-css.php
More file actions
48 lines (42 loc) · 1.11 KB
/
Copy pathcustom-css.php
File metadata and controls
48 lines (42 loc) · 1.11 KB
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
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class CustomCSSPlugin
* @package Grav\Plugin
*/
class CustomCSSPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
/**
* Initialize the plugin
*/
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
if ($this->isAdmin()) {
return;
}
$this->enable([
'onAssetsInitialized' => ['onAssetsInitialized', 0]
]);
}
public function onAssetsInitialized()
{
$this->grav['assets']->addInlineCss($this->config->get('plugins.custom-css.css_inline'));
foreach($this->config->get('plugins.custom-css.css_files', []) as $file) {
if (trim((string) $file['path']) !== '') {
$this->grav['assets']->addCss($file['path'], isset($file['priority']) ? $file['priority'] : null);
}
}
}
}