-
Notifications
You must be signed in to change notification settings - Fork 0
/
barnard_compound_bookreader.module
134 lines (122 loc) · 5.02 KB
/
barnard_compound_bookreader.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* @file
* An Internet Archive Book Reader extension for Islandora Compound Objects.
* Custom behavior for Barnard Digital Collections.
* @blame Benjamin Rosner, @br2490
* @updated 14 Jan 2019
*/
/**
* Implements hook_form().
*
* Admin settings and configuration.
*/
function barnard_compound_bookreader_config($form, &$form_state) {
$form['islandora_compound_bookreader_initial_thumbs'] = [
'#type' => 'textfield',
'#title' => t('IIAB: PIDs to initially display as "thumbs".'),
'#default_value' => variable_get('islandora_compound_bookreader_initial_thumbs', 'BC15-02:01, BC15-04:36, BC15-04:1'),
'#description' => t('Coma separated list of namespaces or PIDs to force to thumbs display in Islandora Internet Archive BookReader.'),
];
$form['islandora_compound_bookreader_initial_1up'] = [
'#type' => 'textfield',
'#title' => t('IIAB: PIDs to initially display as "1up".'),
'#default_value' => variable_get('islandora_compound_bookreader_initial_1up', ''),
'#description' => t('Coma separated list of namespaces or PIDs to force to 1up display in Islandora Internet Archive BookReader.<br /><strong>Scrapbooks (rg BC15.x) need not apply!</strong>'),
];
}
/**
* Implements hook_menu().
*/
function barnard_compound_bookreader_menu() {
$items = [];
$items['admin/islandora/compound_bookreader'] = [
'title' => 'Configure the Compound BookReader extension',
'description' => "Customize the Compund BookReader",
'page callback' => 'drupal_get_form',
'page arguments' => ['barnard_compound_bookreader_config'],
'type' => MENU_NORMAL_ITEM,
'access arguments' => ['administer bc_islandora'],
];
return $items;
}
/**
* Implements hook_preprocess_HOOK().
*/
function barnard_compound_bookreader_preprocess_islandora_internet_archive_bookreader(array &$variables) {
$object = $variables['object'];
$pid = $object->id;
$ns = islandora_get_namespace($pid);
// Barnard has settings in its module for which items should
// be 1up (most IAB items) or thumbs (currently none).
//
// @TODO: Bring these settings over to this module.
$thumbs = explode(', ', variable_get('islandora_compound_bookreader_initial_thumbs'));
$one_ups = explode(', ', variable_get('islandora_compound_bookreader_initial_1up'));
if (in_array($pid, $thumbs) || in_array($ns, $thumbs)) {
drupal_add_js([
'islandoraInternetArchiveBookReader' =>
['bookReaderInitialMode' => 3],
], 'setting');
}
elseif (in_array($pid, $one_ups) || in_array($ns, $one_ups)) {
drupal_add_js([
'islandoraInternetArchiveBookReader' =>
['bookReaderInitialMode' => 1],
], 'setting');
}
$barnard_compound_bookreader = drupal_get_path('module', 'barnard_compound_bookreader');
// This is the extended BookReader that is to be called BEFORE IIAB.
drupal_add_js("$barnard_compound_bookreader/js/compound_book_reader.js",
[
'group' => JS_LIBRARY,
'weight' => -5,
]
);
// This just replaces the default with ours: it hides additional items, and
// is not required for functionality.
drupal_add_js("$barnard_compound_bookreader/js/barnard_islandora_internet_archive_bookreader.js",
[
'group' => JS_LIBRARY,
'weight' => -5,
]
);
}
/**
* Implements hook_preprocess_islandora_compound_prev_next().
*
* This makes the compound navigation block behave in this way:
* the first object inside of me will always be the PARENT object.
* rationale: because compound_objects are a contentType, not a true archival
* object, ever. I simply handle how archival objects get processed.
*
* Allowing anything to be a "compound object" is NOT ADVISED. It is nice
* as an option but is included for capability, most likely.
*
* We'll use a predictable set of classes for our inclusions as they relate to
* the parent and each other.
*
* @TODO some of the variables we kick back are:
* @TODO list vars.
*/
function barnard_compound_bookreader_preprocess_islandora_compound_prev_next(array &$variables) {
// We always create a compound obj and the first object is the parent obj.
$variables['themed_siblings'][0]['class'][] = 'parent';
// This simply parses the label of the object into their matched parts.
foreach ($variables['themed_siblings'] as $key => &$vars) {
if (preg_match("/(page.(\d{1,3})).*(inclusion.(\d{1,3}))/i", $vars['label'], $matches)) {
$classes = [
'inclusion-object',
"inclusion-page-{$matches[2]}",
"inclusion_page-{$matches[2]}-sequence-{$matches[4]}",
];
$vars['class'] = array_merge($vars['class'], $classes);
$vars['label'] = ucfirst($matches[0]);
$vars['inclusion_page'] = $matches[2];
}
if ($variables['sequence'] > 1 && isset($vars['class'][0]) && $vars['class'][0] === 'active') {
$variables['current_inclusion'] = $vars['inclusion_page'];
$variables['themed_siblings'][0]['return_page'] = $vars['inclusion_page'];
}
}
}