-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModule.php
More file actions
110 lines (97 loc) · 3.82 KB
/
Module.php
File metadata and controls
110 lines (97 loc) · 3.82 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php declare(strict_types=1);
namespace Reference;
if (!class_exists(\Common\TraitModule::class)) {
require_once file_exists(dirname(__DIR__) . '/Common/src/TraitModule.php')
? dirname(__DIR__) . '/Common/src/TraitModule.php'
: dirname(__DIR__) . '/Common/TraitModule.php';
}
use Common\Stdlib\PsrMessage;
use Common\TraitModule;
use Laminas\EventManager\Event;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
use Omeka\Module\AbstractModule;
/**
* Reference
*
* Allows to serve an alphabetized and a hierarchical page of links to searches
* for all resources classes and properties of all resources of Omeka S.
*
* @copyright Daniel Berthereau, 2017-2026
* @license http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*/
class Module extends AbstractModule
{
use TraitModule;
const NAMESPACE = __NAMESPACE__;
public function onBootstrap(MvcEvent $event): void
{
parent::onBootstrap($event);
$this->getServiceLocator()->get('Omeka\Acl')
->allow(
[
\Omeka\Permissions\Acl::ROLE_RESEARCHER,
\Omeka\Permissions\Acl::ROLE_AUTHOR,
\Omeka\Permissions\Acl::ROLE_REVIEWER,
\Omeka\Permissions\Acl::ROLE_EDITOR,
\Omeka\Permissions\Acl::ROLE_SITE_ADMIN,
\Omeka\Permissions\Acl::ROLE_GLOBAL_ADMIN,
],
[\Reference\Controller\Admin\ReferenceController::class],
['browse', 'show', 'values']
)
->allow(
null,
[\Reference\Controller\Site\ReferenceController::class],
['browse', 'list']
)
->allow(
null,
[\Reference\Controller\ApiController::class]
);
}
protected function preInstall(): void
{
$services = $this->getServiceLocator();
$plugins = $services->get('ControllerPluginManager');
$translator = $services->get('MvcTranslator');
if (!method_exists($this, 'checkModuleActiveVersion') || !$this->checkModuleActiveVersion('Common', '3.4.84')) {
$message = new \Omeka\Stdlib\Message(
$translator->translate('The module %1$s should be upgraded to version %2$s or later.'), // @translate
'Common', '3.4.84'
);
throw new \Omeka\Module\Exception\ModuleCannotInstallException((string) $message);
}
}
protected function postInstall(): void
{
$services = $this->getServiceLocator();
$messenger = $services->get('ControllerPluginManager')->get('messenger');
if (!extension_loaded('intl')) {
$messenger->addWarning(new PsrMessage(
'The php extension "intl" is recommended to fix issues with diacritic letters.' // @translate
));
}
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
{
$sharedEventManager->attach(
\Omeka\Form\SiteSettingsForm::class,
'form.add_elements',
[$this, 'handleSiteSettings']
);
}
public function handleSiteSettings(Event $event): void
{
// Check site settings, because array options cannot be set by default
// automatically.
$settings = $this->getServiceLocator()->get('Omeka\Settings\Site');
$exist = $settings->get('reference_resource_name');
if ($exist === null) {
$config = $this->getConfig();
$settings->set('reference_options', $config['reference']['site_settings']['reference_options']);
$settings->set('reference_slugs', $config['reference']['site_settings']['reference_slugs']);
}
$this->handleAnySettings($event, 'site_settings');
}
}