This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModule.php
69 lines (53 loc) · 2.07 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
<?php
namespace AgileThemeTools;
use Doctrine\ORM\Events;
use AltText\Db\Event\Listener\DetachOrphanMappings;
use AltText\Entity\AltText as AltTextEntity;
use Omeka\Api\Representation\MediaRepresentation;
use Omeka\Entity\Media as MediaEntity;
use Omeka\Module\AbstractModule;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
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, [\AgileThemeTools\Controller\BlockOptionsAdminController::class]);
$em = $this->getServiceLocator()->get('Omeka\EntityManager');
$em->getEventManager()->addEventListener(
Events::preFlush,
new DetachOrphanMappings
);
}
// Code borrowed from the AltText module (with thanks!). Substitutes dc:description if no Alt tag provided.
// Defaults to the title of the file, which is often just the filename.
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach(
'*',
'view_helper.thumbnail.attribs',
function (Event $event) {
$media = $event->getParam('primaryMedia');
if (!$media) {
return;
}
$attribs = $event->getParam('attribs');
if (empty($attribs['alt'])) {
$item = $media->item();
$description = $item->value('dcterms:description');
$attribs['alt'] = !empty($description) ? htmlspecialchars(strip_tags($description)) : $media->displayTitle();
}
$event->setParam('attribs', $attribs);
}
);
}
}