-
Notifications
You must be signed in to change notification settings - Fork 2
/
coalliance_form_adapter.module
235 lines (222 loc) · 7.43 KB
/
coalliance_form_adapter.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
<?php
// $Id$
/**
* @file
*/
/**
* Implements Hook Menu.
*
* @return array
*/
function coalliance_form_adapter_menu() {
$items['formbuilder/ingest'] = array(
'title' => 'Ingest',
'description' => 'Ingest',
'page callback' => 'drupal_get_form',
'page arguments' => array('coalliance_form_adapter_ingest_form'),
'access arguments' => array('ingest new fedora objects'),
'type' => MENU_CALLBACK,
);
$items['formbuilder/edit'] = array(
'title' => 'Edit Metadata',
'description' => 'Edit Metadata',
'page callback' => 'drupal_get_form',
'page arguments' => array('coalliance_form_adapter_edit_form'),
'access arguments' => array('edit fedora meta data'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Get Ingest Form.
*
* @param array $form_state
* @param string $collection_pid
*
* @return array
*/
function coalliance_form_adapter_ingest_form(array &$form_state, $collection_pid = NULL) {
if (!user_access('ingest new fedora objects')) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return FALSE;
}
module_load_include('inc', 'fedora_repository', 'SecurityClass');
$security_class = new SecurityClass();
if (!$security_class->canIngestHere($collection_pid)) {
// Queries the collection object for a child security datastream and if found parses it
// to determine if this user is allowed to ingest in this collection
// we assume if they are able to modify objects in the collection they can ingest as well.
drupal_set_message(t('You do not have premission to ingest here.'));
return FALSE;
}
if ($collection_pid == NULL) {
$collection_pid = variable_get('fedora_repository_pid', 'islandora:top');
}
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
try {
$ingest_form = new IngestObjectMetadataForm();
$form = $ingest_form->create($collection_pid, NULL, $form_state);
/**
* Hactastic stuff for the work flow module.
*/
$form['cancel'] = array(
'#type' => 'markup',
'#value' => '<input type="button" value="' . t('Cancel') . '" onclick="window.location = \'' . url('fedora/repository/' . $collection_pid) . '\';">',
);
return $form;
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
return array();
}
}
/**
* Validate Ingest Form.
*
* @param array $form
* @param array $form_state
*/
function coalliance_form_adapter_ingest_form_validate(array &$form, array &$form_state) {
if ($form_state['ahah_submission']) {
$form_state['submitted'] = FALSE;
return;
}
if ($form_state['storage']['step'] == 1) {
$form_state['storage']['step']++;
$form_state['rebuild'] = TRUE; // Rebuild for the cancel button.
}
else {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
$errors = form_get_errors();
if (!empty($errors) && !empty($_FILES)) {
drupal_set_message(t('Remember to reattach your files.'));
}
}
/**
* Submit Ingest Form.
*
* @param array $form
* @param array $form_state
*/
function coalliance_form_adapter_ingest_form_submit(array &$form, array &$form_state) {
if ($form_state['ahah_submission']) {
$form_state['submitted'] = FALSE;
return;
}
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
if ($form_state['storage']['step'] == 2) {
try {
$ingest_form = new IngestObjectMetadataForm();
$ingest_form->submit($form, $form_state);
if (module_exists('islandora_workflow')) {
module_load_include('collection.inc', 'islandora_workflow');
module_load_include('permissions.inc', 'islandora_workflow');
module_load_include('inc', 'islandora_workflow');
$pid = $form_state['values']['pid'];
$parent_pid = islandora_workflow_get_object_parent($pid);
if (islandora_workflow_is_collection_workflow_tracked($parent_pid)) {
if (islandora_workflow_user_collection_permission_check($parent_pid)) {
islandora_workflow_init_workflow($pid);
}
}
}
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
$form_state['rebuild'] = TRUE;
}
}
}
/**
* Get Edit Form.
*
* @param array $form_state
* @param string $collection_pid
*
* @return array
*/
function coalliance_form_adapter_edit_form(array &$form_state, $pid=NULL) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
if (!$pid) {
$pid = variable_get('fedora_repository_pid', 'islandora:top');
}
$connection_helper = new ConnectionHelper();
$client = $connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
try {
$edit_form = new EditObjectMetadataForm();
$form = $edit_form->create($pid, $client, $form_state);
$form['cancel'] = array(
'#type' => 'markup',
'#value' => '<input type="button" value="' . t('Cancel') . '" onclick="window.location = \'' . url('fedora/repository/' . $pid) . '\';">',
);
return $form;
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
return array();
}
}
/**
* Validate Edit Form.
*
* @param array $form
* @param array $form_state
*/
function coalliance_form_adapter_edit_form_validate(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 1) {
$form_state['storage']['step']++;
$form_state['rebuild'] = TRUE;
}
else {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
}
/**
* Submit Edit Form.
*
* @param array $form
* @param array $form_state
*/
function coalliance_form_adapter_edit_form_submit(array &$form, array &$form_state) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
try {
$edit_form = new EditObjectMetadataForm();
$edit_form->submit($form, $form_state);
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
$form_state['rebuild'] = TRUE;
}
}
/**
*
*/
function coalliance_form_adapter_restore_forms_to_default($form, &$form_state) {
$form_name = $form[0]['default']['#post']['form_name'];
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
$module_path = drupal_get_path('module', 'coalliance_form_adapter');
if(file_exists($module_path . '/' . $form_name . '.xml')) {
$doc = new DOMDocument();
$doc->load($module_path . '/' . $form_name . '.xml');
if (!XMLFormDatabase::Exists($form_name)) {
XMLFormDatabase::Create($form_name, $doc);
}
else {
XMLFormDatabase::Update($form_name, $doc);
}
}
}
function coalliance_form_adapter_form_xml_form_builder_main_alter(array &$form, array &$form_state) {
$form[0]['default'] = array(
'#type' => 'submit',
'#value' => t('Restore Defaults'),
'#name' => 'default',
'#submit' => array('coalliance_form_adapter_restore_forms_to_default')
);
}