/
Module.php
61 lines (55 loc) · 1.69 KB
/
Module.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
<?php
namespace CSSEditor;
use Omeka\Module\AbstractModule;
use Omeka\Permissions\Assertion\HasSitePermissionAssertion;
use Laminas\EventManager\Event;
use Laminas\Mvc\MvcEvent;
use Laminas\EventManager\SharedEventManagerInterface;
class Module extends AbstractModule
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function onBootstrap(MvcEvent $event)
{
parent::onBootstrap($event);
$acl = $this->getServiceLocator()->get('Omeka\Acl');
$acl->allow(
null,
'CSSEditor\Controller\Site\Index'
);
$acl->allow(
null,
'CSSEditor\Controller\Admin\Index'
);
$acl->allow(
null,
'Omeka\Entity\Site',
'css-editor-modify',
new HasSitePermissionAssertion('admin')
);
}
public function addCSS(Event $event)
{
$services = $this->getServiceLocator();
if (!$services->get('Omeka\Status')->isSiteRequest()) {
return;
}
$view = $event->getTarget();
$view->headLink()->appendStylesheet($view->url('site/css-editor', [
'site-slug' => $view->site->slug(),
]));
$siteSettings = $services->get('Omeka\Settings\Site');
$externalCss = $siteSettings->get('css_editor_external_css');
if ($externalCss) {
foreach ($externalCss as $uri) {
$view->headLink()->appendStylesheet($uri);
}
}
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach('*', 'view.layout', [$this, 'addCSS']);
}
}