forked from Islandora/islandora_solr_metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_solr_metadata.module
267 lines (255 loc) · 9.34 KB
/
islandora_solr_metadata.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* @file
* The main module file for the islandora_solr_metadata module.
*/
/**
* Implements hook_menu().
*/
function islandora_solr_metadata_menu() {
$items = array();
$items['admin/islandora/search/islandora_solr/metadata'] = array(
'title' => 'Metadata Display',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
'page callback' => 'islandora_solr_metadata_admin_page_callback',
'access arguments' => array('administer islandora_solr_metadata'),
'file' => 'includes/admin.inc',
);
$items['admin/islandora/search/islandora_solr_metadata/config/%'] = array(
'title callback' => 'islandora_solr_metadata_display_configuration_name',
'title arguments' => array(5),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_solr_metadata_config_form', 5),
'access callback' => 'islandora_solr_metadata_access',
'access arguments' => array(5),
'file' => 'includes/config.inc',
);
$items['admin/islandora/search/islandora_solr_metadata/config/%/%'] = array(
'title callback' => 'islandora_solr_metadata_display_field_configuration_name',
'title arguments' => array(5, 6),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_solr_metadata_config_field_form', 5, 6),
'access callback' => 'islandora_solr_metadata_field_configuration_access',
'access arguments' => array(5, 6),
'file' => 'includes/config.inc',
);
$items['admin/islandora/search/islandora_solr_metadata/config/delete/%'] = array(
'title' => 'Delete display configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_solr_metadata_delete_config_form', 6),
'access callback' => 'islandora_solr_metadata_access',
'access arguments' => array(6),
'file' => 'includes/delete.inc',
);
return $items;
}
/**
* Implements hook_theme().
*/
function islandora_solr_metadata_theme() {
return array(
'islandora_solr_metadata_management_table' => array(
'render element' => 'table',
'file' => 'theme/theme.inc',
),
'islandora_solr_metadata_display' => array(
'template' => 'theme/islandora-solr-metadata-display',
// We can add PIDs to the end of this pattern in our preprocess function
// and templates will be able to have have a pid appended to the
// template name to overide a template on a per object basis.
// An example template might be named:
// "islandora-solr-metadata-display--islandora-27.tpl.php".
'pattern' => 'islandora_solr_metadata_display__',
'variables' => array(
'islandora_object' => NULL,
'print' => FALSE,
'solr_fields' => array(),
'found' => FALSE,
'associations' => array(),
),
'file' => 'theme/theme.inc',
),
'islandora_solr_metadata_description' => array(
'template' => 'theme/islandora-solr-metadata-description',
// We can add PIDs to the end of this pattern in our preprocess function
// and templates will be able to have have a pid appended to the
// template name to overide a template on a per object basis.
// An example template might be named:
// "islandora-solr-metadata-description--islandora-27.tpl.php".
'pattern' => 'islandora_solr_metadata_description__',
'variables' => array(
'islandora_object' => NULL,
'solr_fields' => array(),
'combine' => TRUE,
'found' => FALSE,
'associations' => array(),
),
'file' => 'theme/theme.inc',
),
);
}
/**
* Implements hook_permission().
*/
function islandora_solr_metadata_permission() {
return array(
'administer islandora_solr_metadata' => array(
'title' => 'Create and manage metadata display configurations',
),
);
}
/**
* Access callback for accessing a configuration based upon ID.
*
* @param int $configuration_id
* The configuration ID of the list we are accessing.
*
* @return bool
* TRUE if the user has permission and the list exists, FALSE otherwise.
*/
function islandora_solr_metadata_access($configuration_id) {
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
return islandora_solr_metadata_configuration_exists($configuration_id) && user_access('administer islandora_solr_metadata');
}
/**
* Access callback for accessing field configuration.
*
* @param int $configuration_id
* The configuration ID of the list we are accessing.
* @param string $escaped_field
* The name of the Solr field with slashes escaped, as per
* islandora_solr_replace_slashes().
*
* @return bool
* TRUE if the user has access to the configuration and the field exists in
* the configuration, FALSE otherwise.
*/
function islandora_solr_metadata_field_configuration_access($configuration_id, $escaped_field) {
module_load_include('inc', 'islandora_solr', 'includes/utilities');
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
return islandora_solr_metadata_access($configuration_id) && array_key_exists(islandora_solr_restore_slashes($escaped_field), islandora_solr_metadata_get_fields($configuration_id, FALSE));
}
/**
* Implements hook_features_api().
*/
function islandora_solr_metadata_features_api() {
$mod_path = drupal_get_path('module', 'islandora_solr_metadata');
return array(
'islandora_solr_metadata_configurations' => array(
'name' => t('Islandora Solr Metadata Configurations'),
'file' => "$mod_path/includes/configurations.features.inc",
'default_hook' => 'islandora_solr_metadata_configurations_default_fields',
'feature_source' => TRUE,
),
);
}
/**
* Title callback for the configuration display.
*
* @param int $configuration_id
* The ID of the configuration we are retrieving the name of.
*
* @return string
* The name of the configuration that is to be edited.
*/
function islandora_solr_metadata_display_configuration_name($configuration_id) {
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
$configuration_name = islandora_solr_metadata_retrieve_configuration_name($configuration_id);
return t('@configuration_name display configuration', array(
'@configuration_name' => $configuration_name,
));
}
/**
* Title callback for the field configuration display.
*
* @param int $configuration_id
* The ID of the configuration we are retrieving the name of.
*
* @return string
* The name of the configuration that is to be edited.
*/
function islandora_solr_metadata_display_field_configuration_name($configuration_id, $escaped_field_name) {
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
module_load_include('inc', 'islandora_solr', 'includes/utilities');
$configuration_name = islandora_solr_metadata_retrieve_configuration_name($configuration_id);
return t('@field configuration', array(
'@field' => islandora_solr_restore_slashes($escaped_field_name),
));
}
/**
* Implements hook_i18n_string_info().
*/
function islandora_solr_metadata_i18n_string_info() {
return array(
'islandora_solr_metadata' => array(
'title' => t('Islandora Solr Metadata'),
'description' => t('Translatable configuration names and display labels.'),
'format' => FALSE,
'list' => TRUE,
),
);
}
/**
* Implements hook_islandora_metadata_display_info().
*/
function islandora_solr_metadata_islandora_metadata_display_info() {
return array(
'islandora_solr_metadata' => array(
'label' => t('Islandora Solr Metadata'),
'description' => t('Metadata display driven by the Islandora Solr Search module'),
'metadata callback' => 'islandora_solr_metadata_display_callback',
'description callback' => 'islandora_solr_metadata_description_callback',
'configuration' => 'admin/islandora/search/islandora_solr/metadata',
),
);
}
/**
* Metadata display callback for rendering metadata from Solr.
*
* @param AbstractObject $object
* An AbstractObject representing an object within Fedora.
* @param bool $print
* Whether this is for printing purposes.
*
* @return string
* Markup representing the metadata display pulled from Solr.
*/
function islandora_solr_metadata_display_callback(AbstractObject $object, $print = FALSE) {
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
$elements = array(
'islandora_object' => $object,
'print' => $print,
'associations' => islandora_solr_metadata_get_associations_by_cmodels($object->models),
);
drupal_alter('islandora_solr_metadata_display_elements', $elements);
if (count($elements['associations']) > 0) {
return theme('islandora_solr_metadata_display', $elements);
}
else {
return FALSE;
}
}
/**
* Metadata display callback for rendering metadata from Solr.
*
* @param AbstractObject $object
* An AbstractObject representing an object within Fedora.
*
* @return string
* Markup representing the metadata display pulled from Solr.
*/
function islandora_solr_metadata_description_callback(AbstractObject $object) {
module_load_include('inc', 'islandora_solr_metadata', 'includes/db');
$elements = array(
'islandora_object' => $object,
'associations' => islandora_solr_metadata_get_associations_by_cmodels($object->models),
);
drupal_alter('islandora_solr_metadata_description_elements', $elements);
if (count($elements['associations']) > 0) {
return theme('islandora_solr_metadata_description', $elements);
}
else {
return FALSE;
}
}