-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_multilingual.module
181 lines (164 loc) · 6.17 KB
/
islandora_multilingual.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
<?php
/**
* @file
* Module relating to the CEC_multilingual object model
*/
define('ISLANDORA_MULTILINGUAL_CMODEL', 'islandora:CEC_multilingual');
/**
* Implements hook_menu()
*/
function islandora_multilingual_menu() {
$items = array();
$items['admin/islandora/multilingual'] = array(
'title' => 'Multilingual',
'description' => 'Choose languages for Multilingual Islandora to enable',
'file' => 'admin/multilingual.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multilingual_admin_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_variable_info()
*/
function islandora_multilingual_variable_info() {
$variable = array();
$variable['islandora_languages'] = array(
'title' => t('Islandora languages'),
'description' => t('Languages in which multilingual metadata will be available. Enter a comma-separated list of upper-case language abbreviations. E.g. for English and French, enter "EN,FR" -- note, no space after the comma.'),
'type' => 'string',
);
}
/**
* Implements hook_theme().
*/
function islandora_multilingual_theme($existing, $type, $theme, $path) {
return array(
// this includes some general theming that should be moved out.
'islandora_multilingual' => array(
'file' => 'theme/islandora_multilingual.theme.inc',
'template' => 'theme/islandora-multilingual',
'pattern' => 'islandora_multilingual__',
'variables' => array('islandora_object' => NULL),
),
'language_links' => array(
'file' => 'theme/language_links.theme.inc',
'template' => 'theme/language-links',
'variables' => array('lang_array' => array()),
),
// more general than multilingual
'display_title' => array(
'file' => 'theme/display_title.theme.inc',
'template' => 'theme/display-title',
'variables' => array('title' => '', 'subTitle' => ''),
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*
*/
function islandora_multilingual_islandora_view_object($object, $page_number, $page_size) {
if (in_array(ISLANDORA_MULTILINGUAL_CMODEL, $object->models)) {
$result = array();
$result['Multilingual View'] = theme('islandora_multilingual', array('islandora_object' => $object));
return $result;
}
}
/**
* Implements hook_islandora_ingest_steps().
*
* Our custom ingest form lets you select the language of the uploaded file.
*/
function islandora_multilingual_islandora_CEC_multilingual_islandora_ingest_steps(array $configuration) {
if (in_array(ISLANDORA_MULTILINGUAL_CMODEL, $configuration['islandora']['shared_storage']['models'])) {
return array(
'islandora_multlingual_pdf_file_upload' => array(
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_multilingual_pdf_upload_form',
'module' => 'islandora_multilingual',
'file' => 'includes/multilingual_upload.form.inc',
)
);
}
}
/**
* Implements hook_islandora_datastream_ingested().
*
* If a MODS ds was ingested, create the other languages.
* If an OBJ ds was ingested, create the thumbnails.
*/
function islandora_multilingual_islandora_datastream_ingested($object, $datastream) {
if (preg_match('/MODS/', $datastream->id) === 1) {
$enabled_languages = explode(',', variable_get('islandora_languages', 'EN,'));
$missing_ds = FALSE;
foreach ($enabled_languages as $lang) {
if (!isset($object['MODS-' . $lang])) {
$missing_ds = TRUE;
}
}
if ($missing_ds) {
module_load_include('inc', 'islandora_multilingual', 'includes/Multilingual');
sleep(2);
multilingual_create_multiple_mods_datastreams($object, $datastream);
module_invoke_all('islandora_multilingual_mods_sync', $object, $datastream);
}
}
if (preg_match('/OBJ.*/', $datastream->id) === 1) {
islandora_multilingual_create_all_derivatives($object, $datastream->id);
}
}
/**
* Implements hook_form_FORM_ID_alter()
*
* In the Islandora edit datastream form,
* - add our custom validation function
* - fill the 'label' field
*/
function islandora_multilingual_form_xml_form_builder_edit_datastream_form_alter(&$form, $form_state) {
if (in_array(ISLANDORA_MULTILINGUAL_CMODEL, $form_state['datastream']->parent->models) and !isset($form['available_forms'])) {
array_unshift($form['#validate'], 'islandora_multilingual_datastream_form_validate');
multilingual_fill_mods_label_field($form, $form_state);
}
}
/**
* Implements hook_form_FORM_ID_alter()
*
* In the Islandora ingest form,
* - add our custom validate function
*/
function islandora_multilingual_form_islandora_ingest_form_alter(&$form, $form_state) {
if (isset($form_state['islandora']['objects'])) {
if (isset($form_state['islandora']['objects'][0]) and in_array(ISLANDORA_MULTILINGUAL_CMODEL, $form_state['islandora']['objects'][0]->models)) {
array_unshift($form['#validate'], 'islandora_multilingual_datastream_form_validate');
}
}
}
function multilingual_fill_mods_label_field(&$form, $form_state) {
$form['label']['#default_value'] = $form_state['datastream']->parent->label;
$form['label']['#access'] = FALSE;
}
/*
* This custom validation function runs after you edit metadata using a mods form
* either when ingesting or when editing an existing datastream.
*
* It marks this datastream as "master".
*
*/
function islandora_multilingual_datastream_form_validate(array &$form, array &$form_state) {
// Determine whether the form has been submitted (since the form validation function
// also runs when the user creates/deletes tab form elements).
$form_was_submitted = FALSE;
if (($form['#form_id'] == 'islandora_ingest_form') and ($form_state['islandora']['step_id'] == 'xml_form_builder_metadata_step') and $form_state['submitted']) {
$form_was_submitted = TRUE;
} elseif (($form['#form_id'] == 'xml_form_builder_edit_datastream_form') and ($form_state['submitted'])) {
$form_was_submitted = TRUE;
}
if ($form_was_submitted) {
// Mark this datastream as "master"
$form_state['values']['master'] = 'yes';
}
}