-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_doi_framework.module
154 lines (142 loc) · 4.79 KB
/
islandora_doi_framework.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
<?php
/**
* @file
* Module file.
*/
/**
* Implements hook_menu().
*/
function islandora_doi_framework_menu() {
$items = array();
$items['islandora/object/%islandora_object/manage/assign_doi'] = array(
'title' => 'DOI',
'access arguments' => array('manage DOIs for Islandora objects'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_doi_framework_manage_doi'),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
return $items;
}
/**
* Implements hook_permission().
*/
function islandora_doi_framework_permission() {
return array(
'manage DOIs for Islandora objects' => array(
'title' => t('Manage DOIs for Islandora objects'),
'description' => t('Assign and update DOIs for Islandora objects using the Islandora DOI Framework'),
),
);
}
/**
* Form definition for assigning a DOI.
*/
function islandora_doi_framework_manage_doi() {
$form = array();
$pid = arg(2);
$object = islandora_object_load($pid);
$form['islandora_doi_pid'] = array(
'#type' => 'value',
'#value' => $pid,
);
$dois = module_invoke_all('islandora_doi_framework_check_for_doi', $pid);
$dois = array_unique($dois);
if (count($dois)) {
$dois = array_unique($dois);
// Put any non-boolean values at beginning of array.
rsort($dois);
}
$handlers = module_invoke_all('islandora_doi_framework_form_handlers');
// There is a DOI already, so we're updating.
if (count($dois) && strlen($dois[0])) {
$form['islandora_doi_framework_doi_exists_message'] = array(
'#markup' => t("This object already has a DOI: !doi. Do you want to update the object's information associated with the DOI?",
array('!doi' => $dois[0])),
'#prefix' => '<div class="messages warning">',
'#suffix' => '</div>',
'#weight' => -10,
);
$form['islandora_doi_framework_update_doi'] = array(
'#type' => 'submit',
'#value' => t('Update DOI'),
'#submit' => array('islandora_doi_framework_update_doi_submit'),
'#weight' => 10,
);
$form['islandora_doi_doi'] = array(
'#type' => 'value',
'#value' => $dois[0],
);
if (count($handlers)) {
foreach ($handlers['update_doi']['submit'] as $handler) {
$form['#submit'][] = $handler;
}
foreach ($handlers['update_doi']['validate'] as $handler) {
$form['#validate'][] = $handler;
}
}
$form['#submit'][] = 'islandora_doi_framework_manage_doi_update_submit_';
return $form;
}
// There is no DOI yet, so we're minting.
else {
$form['islandora_doi_object_message'] = array(
'#prefix' => '<div class="messages warning">',
'#markup' => t("You are about to assign a DOI to object !pid (!label)",
array('!pid' => $pid, '!label' => $object->label)),
'#suffix' => '</div>',
'#weight' => -10,
);
$form['islandora_doi_framework_assign_doi'] = array(
'#type' => 'submit',
'#value' => t('Assign DOI'),
'#weight' => 10,
);
if (count($handlers)) {
foreach ($handlers['assign_doi']['submit'] as $handler) {
$form['#submit'][] = $handler;
}
foreach ($handlers['assign_doi']['validate'] as $handler) {
$form['#validate'][] = $handler;
}
}
$form['#submit'][] = 'islandora_doi_framework_manage_doi_assign_submit_';
return $form;
}
}
/**
* Form submit handler.
*
* We provide a default submit handler in case no submodules provide any.
* We append a "_" to the end of the function name so it doesn't overwrite
* the '#submit' property defined in the form.
*/
function islandora_doi_framework_manage_doi_assign_submit_($form, &$form_state) {
module_load_include('inc', 'islandora_doi_framework', 'includes/utilities');
$pid = $form_state['values']['islandora_doi_pid'];
// We pass the form and form state into hook implementations so they
// have access to the form values.
if ($doi = islandora_doi_framework_mint_doi($pid, $form, $form_state)) {
islandora_doi_framework_persist_doi($doi, $pid, $form, $form_state);
$form_state['redirect'] = 'islandora/object/' . $pid;
}
}
/**
* Form submit handler.
*
* We provide a default submit handler in case no submodules provide any.
* We append a "_" to the end of the function name so it doesn't overwrite
* the '#submit' property defined in the form.
*
* "Update" refers to changing either or both the URL and metadata,
* not the DOI itself.
*/
function islandora_doi_framework_manage_doi_update_submit_($form, &$form_state) {
module_load_include('inc', 'islandora_doi_framework', 'includes/utilities');
$pid = $form_state['values']['islandora_doi_pid'];
$doi = $form_state['values']['islandora_doi_doi'];
$updated = islandora_doi_framework_update($pid, $doi, $form, $form_state);
if ($updated) {
$form_state['redirect'] = 'islandora/object/' . $pid;
}
}