-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-wysiwyg.php
97 lines (85 loc) · 2.45 KB
/
admin-wysiwyg.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
<?php
namespace Grav\Plugin;
use Grav\Common\Assets;
use Grav\Common\Page\Types;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class AdminWysiwygPlugin
* @package Grav\Plugin
*/
class AdminWysiwygPlugin extends Plugin
{
/**
* Bump up the priority of our blueprints over the `admin` plugin.
*
* @var array
*/
public $features = [
'blueprints' => 10000,
];
/**
* @var string
*/
private $theme;
/**
* @return array
*
* Core list of events that the plugin wants to listen to.
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
];
}
/**
* Initialize the plugin
*/
public function onPluginsInitialized()
{
// Enable the main event we are interested in
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 999],
]);
// Get theme for admin
$this->theme = $this->config->get('plugins.admin.theme', 'grav');
}
/**
* Get list of form field types specified in this plugin. Only special types needs to be listed.
*
* @return array
*/
public function getFormFieldTypes()
{
return [
'wysiwyg' => [
'input@' => false
],
];
}
/**
* Add twig paths to plugin templates.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
public function onTwigSiteVariables()
{
if (!$this->isAdmin()) {
return;
}
$pluginBase = 'plugin://admin-wysiwyg';
/** @var Assets $assets */
$assets = $this->grav['assets'];
$assets->addCss($pluginBase . '/css-compiled/trumbowyg.min.css', -10);
$assets->addCss($pluginBase . '/css-compiled/wysiwyg.css', -11);
$assets->addJs($pluginBase . '/js-compiled/trumbowyg.min.js', -10);
$assets->addJs($pluginBase . '/node_modules/trumbowyg/plugins/preformatted/trumbowyg.preformatted.js', -11);
$assets->addJs($pluginBase . '/node_modules/to-markdown/dist/to-markdown.js', -12);
$assets->addJs($pluginBase . '/node_modules/showdown/dist/showdown.min.js', -13);
$assets->addJs($pluginBase . '/js-compiled/wysiwyg.js', -14);
}
}