-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_uiig_edit_metadata.module
62 lines (56 loc) · 1.96 KB
/
islandora_uiig_edit_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
<?php
/**
* Implements hook_menu().
*/
function islandora_uiig_edit_metadata_menu() {
$items = array();
// Scan all form associations to build edit links.
module_load_include('inc', 'xml_form_builder', 'includes/associations');
module_load_include('inc', 'islandora', 'includes/utilities');
$associations = xml_form_builder_get_associations();
$dsids_to_include = array();
foreach ($associations as $association) {
if (!isset($dsids_to_include[$association['dsid']])) {
$dsids_to_include[$association['dsid']] = array($association['content_model']);
}
else {
$dsids_to_include[$association['dsid']][] = $association['content_model'];
}
}
foreach($dsids_to_include as $dsid => $cmodels) {
$items['islandora/object/%islandora_object/edit_' . $dsid] = array(
'title' => t('Edit Metadata'),
'page callback' => 'islandora_uiig_edit_metadata_edit_datastream',
'page arguments' => array(2, $dsid),
'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_uiig_edit_metadata_edit_datastream_access',
'access arguments' => array(2, $dsid, $cmodels),
);
}
return $items;
}
/**
* Callback to edit the datastream.
*/
function islandora_uiig_edit_metadata_edit_datastream($object, $dsid) {
if (isset($object[$dsid])) {
module_load_include('inc', 'islandora', 'includes/datastream');
return islandora_edit_datastream($object[$dsid]);
}
else {
// No edit implementations.
drupal_set_message(t('This datastream does not exist.'));
drupal_goto("islandora/object/{$object->id}/manage/datastreams");
}
}
/**
* Access callback for editing datastreams also checks if datastream is present.
*/
function islandora_uiig_edit_metadata_edit_datastream_access($object, $dsid, $cmodels) {
if (!isset($object[$dsid])) {
return FALSE;
}
elseif (count(array_intersect($object->models, $cmodels)) > 0) {
return islandora_datastream_access(ISLANDORA_METADATA_EDIT, $object[$dsid]);
}
}