-
Notifications
You must be signed in to change notification settings - Fork 5
/
SwagTinyMceCustomFont.php
59 lines (45 loc) · 1.8 KB
/
SwagTinyMceCustomFont.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
<?php
namespace SwagTinyMceCustomFont;
use Doctrine\Common\Collections\ArrayCollection;
use Shopware\Components\Theme\LessDefinition;
class SwagTinyMceCustomFont extends \Shopware\Components\Plugin
{
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PostDispatchSecure_Backend_Index' => 'onBackendIndexPostDispatch',
'Theme_Compiler_Collect_Plugin_Less' => 'onCollectPluginLess'
];
}
/**
* @param \Enlight_Controller_EventArgs|\Enlight_Event_EventArgs $args
*/
public function onBackendIndexPostDispatch(\Enlight_Event_EventArgs $args)
{
$controller = $args->getSubject();
$view = $controller->View();
$config = $this->container->get('shopware.plugin.config_reader')->getByPluginName($this->getName());
$view->assign('tinyMceCustomFontConfig', $config);
$view->assign('tinyMceCacheBuster', md5(json_encode($config)));
$view->addTemplateDir($this->getPath() . '/Resources/Views');
$view->extendsTemplate('backend/swag_tiny_mce_custom_font/include.tpl');
}
public function onCollectPluginLess() {
$lessFiles = [
$this->getPath() . '/Resources/Views/frontend/_public/src/less/all.less'
];
$config = $this->container->get('shopware.plugin.config_reader')->getByPluginName($this->getName());
if (!$config['urls']) {
return new ArrayCollection();
}
$fontUrls = explode("\n", $config['urls']);
$fontUrls = array_filter($fontUrls);
$fonts = [];
foreach($fontUrls as $file) {
$fonts[] = new LessDefinition([
'fontUrl' => '"' . $file . '"'
], $lessFiles, $this->getPath());
}
return new ArrayCollection($fonts);
}
}