forked from patdunlavey/islandora_mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_mirador.module
76 lines (65 loc) · 2.27 KB
/
islandora_mirador.module
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
<?php
/**
* @file
* Supports Islandora submodule islandora_mirador.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\islandora_mirador\IslandoraMiradorPluginPluginBase;
use Drupal\islandora_mirador\IslandoraMiradorPluginInterface;
/**
* Implements hook_theme().
*/
function islandora_mirador_theme() {
return [
'mirador' => [
'variables' => [
'iiif_manifest_url' => NULL,
'mirador_view_id' => NULL,
],
'template' => 'mirador',
],
];
}
/**
* Implements template_preprocess_*().
*/
function template_preprocess_mirador(&$variables) {
$variables['mirador_view_id'] = Html::getUniqueId($variables['mirador_view_id']);
$variables['#attached']['drupalSettings']['mirador_view_id'] = $variables['mirador_view_id'];
/**
* @var \Drupal\islandora_mirador\IslandoraMiradorPluginManager
*/
$mirador_plugin_manager = \Drupal::service('plugin.manager.islandora_mirador');
/**
* @var \Drupal\Core\Config\ImmutableConfig
*/
$config = Drupal::service('config.factory')->get('islandora_mirador.settings');
$mirador_plugins = $mirador_plugin_manager->getDefinitions();
$enabled_plugins = $config->get('mirador_enabled_plugins');
$variables['#attached']['drupalSettings']['mirador_enabled_plugins'] = array_filter(array_values($enabled_plugins));
$window_config = [];
foreach ($mirador_plugins as $plugin_id => $plugin_definition) {
if ($enabled_plugins[$plugin_id]) {
$plugin_instance = $mirador_plugin_manager->createInstance($plugin_id);
/**
* @var Drupal\islandora_mirador\IslandoraMiradorPluginInterface
*/
$plugin_instance->windowConfigAlter($window_config);
}
}
$variables['#attached']['drupalSettings']['mirador_window_settings'] = $window_config;
}
/**
* Implements hook_library_info_alter().
*/
function islandora_mirador_library_info_alter(&$libraries, $extension) {
if ($extension == 'islandora_mirador') {
$config = \Drupal::service('config.factory')->get('islandora_mirador.settings');
if ($config->get('mirador_library_installation_type') == 'local') {
unset($libraries['mirador']['remote']);
unset($libraries['mirador']['license']);
$libraries['mirador']['js']['/libraries/mirador/dist/main.js'] = [];
}
}
}