forked from omeka-s-modules/ValueSuggest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
77 lines (72 loc) · 2.4 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace ValueSuggest;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\Event;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
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, 'ValueSuggest\Controller\Index', 'proxy');
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach(
'Omeka\Controller\Admin\Item',
'view.add.after',
[$this, 'prepareResourceForm']
);
$sharedEventManager->attach(
'Omeka\Controller\Admin\Item',
'view.edit.after',
[$this, 'prepareResourceForm']
);
$sharedEventManager->attach(
'Omeka\Controller\Admin\ItemSet',
'view.add.after',
[$this, 'prepareResourceForm']
);
$sharedEventManager->attach(
'Omeka\Controller\Admin\ItemSet',
'view.edit.after',
[$this, 'prepareResourceForm']
);
$sharedEventManager->attach(
'Omeka\Controller\Admin\Media',
'view.add.after',
[$this, 'prepareResourceForm']
);
$sharedEventManager->attach(
'Omeka\Controller\Admin\Media',
'view.edit.after',
[$this, 'prepareResourceForm']
);
}
/**
* Prepare resource forms for value suggest.
*
* @see https://github.com/devbridge/jQuery-Autocomplete
* @param Event $event
*/
public function prepareResourceForm(Event $event)
{
$view = $event->getTarget();
$assetUrl = $view->plugin('assetUrl');
$view->headLink()
->appendStylesheet($assetUrl('css/valuesuggest.css', 'ValueSuggest'));
$view->headScript()
->appendFile($assetUrl('js/jQuery-Autocomplete/1.2.26/jquery.autocomplete.min.js', 'ValueSuggest'))
->appendFile($assetUrl('js/valuesuggest.js', 'ValueSuggest'))
->appendScript(sprintf(
'var valueSuggestProxyUrl = "%s";',
$view->escapeJs($view->url('admin/value-suggest/proxy'))
));
}
}