-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtripal_file.module
executable file
·360 lines (330 loc) · 9.42 KB
/
tripal_file.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* @file
* This file contains all Drupal hooks for the module other than any
* node hooks and block hooks. Those go in the [module name].chado_node.inc file
* and [module_name].blocks.inc respectively
*
*/
// EXPLANATION: include any files needed for this module. That includes any
// API file, the theme file, or include files.
require_once('api/tripal_file.api.inc');
require_once('theme/tripal_file.theme.inc');
require_once('includes/tripal_file.admin.inc');
/**
* Implements hook_menu().
*/
function tripal_file_menu() {
// tripal file administration page
$items['admin/tripal/extension/tripal_file'] = [
'title' => 'Tripal File User Interface',
'description' => 'A module for associating files with Tripal content and for accessing files via web services.',
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_file_admin_form'],
'access arguments' => ['administer tripal'],
'type' => MENU_NORMAL_ITEM,
];
$items['admin/tripal/extension/tripal_file/config'] = [
'title' => 'Configuration',
'type' => MENU_DEFAULT_LOCAL_TASK,
];
$items['admin/tripal/extension/tripal_file/help'] = [
'title' => 'Help',
'page callback' => 'theme',
'page arguments' => ['tripal_file_help'],
'access arguments' => ['administer tripal'],
'type' => MENU_LOCAL_TASK,
];
// Autocomplete for e.g. sbo__relationship widget.
$items['admin/tripal/storage/chado/auto_name/file/%'] = [
'page callback' => 'chado_autocomplete_file',
'page arguments' => [6],
'access arguments' => ['access content'],
'file' => 'api/tripal_file.api.inc',
'file path' => drupal_get_path('module', 'tripal_file'),
'type' => MENU_CALLBACK,
];
return $items;
}
/**
* Implements hook_theme().
*/
function tripal_file_theme() {
// Module Help
$path = drupal_get_path('module', 'tripal_file');
$items['tripal_file_help'] = [
'template' => 'tripal_file_help',
'path' => "$path/theme",
];
return $items;
}
/**
* Implements hook_help().
*/
function tripal_file_help($path, $arg) {
if ($path == 'admin/help#tripal_file') {
return theme('tripal_file_help', []);
}
}
/**
* Implements hook_views_api()
*
* This hook tells drupal that there is views support for
* this module which then automatically includes the tripal_db.views.inc
* where all the views integration code is found.
*
* @ingroup tripal_file
*/
function tripal_file_views_api() {
return [
'api' => 3.0,
];
}
/**
* Implements hook_bundle_fields_info().
*
* This is a Tripal defined hook that supports integration with the
* TripalEntity field.
*/
function tripal_file_bundle_fields_info($entity_type, $bundle) {
$info = [];
$chado_bundle = db_select('chado_bundle', 'cb')
->fields('cb')
->condition('bundle_id', $bundle->id)
->execute()
->fetchObject();
if ($chado_bundle->data_table == 'file') {
$info['schema__itemlocation'] = [
'field_name' => 'schema__itemlocation',
'type' => 'schema__itemlocation',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'locked' => FALSE,
'storage' => [
'type' => 'field_chado_storage',
],
];
$info['schema__license'] = [
'field_name' => 'schema__license',
'type' => 'schema__license',
'cardinality' => 1,
'locked' => FALSE,
'storage' => [
'type' => 'field_chado_storage',
],
];
$info['sio__references_file'] = [
'field_name' => 'sio__references_file',
'type' => 'sio__references_file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'locked' => FALSE,
'storage' => [
'type' => 'field_chado_storage',
],
];
}
// If a _file linker table exists for the base data table.
if (chado_table_exists($chado_bundle->data_table . '_file')) {
$info['sio__file'] = [
'field_name' => 'sio__file',
'type' => 'sio__file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'locked' => FALSE,
'storage' => [
'type' => 'field_chado_storage',
],
];
}
return $info;
}
/**
* Implements hook_create_tripalfield_instance().
*
* This is a Tripal defined hook that supports integration with the
* TripalEntity field.
*/
function tripal_file_bundle_instances_info($entity_type, $bundle) {
$info = [];
$chado_bundle = db_select('chado_bundle', 'cb')
->fields('cb')
->condition('bundle_id', $bundle->id)
->execute()
->fetchObject();
if ($chado_bundle->data_table == 'file') {
$info['schema__itemlocation'] = [
'field_name' => 'schema__itemlocation',
'entity_type' => 'TripalEntity',
'bundle' => $bundle->name,
'label' => 'Download',
'description' => 'The download location of the file.',
'required' => TRUE,
'settings' => [
'auto_attach' => TRUE,
'chado_table' => 'fileloc',
'chado_column' => 'file_id',
'base_table' => 'file',
'term_accession' => 'itemLocation',
'term_vocabulary' => 'schema',
'term_name' => 'itemLocation',
],
'widget' => [
'type' => 'schema__itemlocation_widget',
'settings' => [
'display_label' => 1,
],
],
'display' => [
'default' => [
'label' => 'inline',
'type' => 'schema__itemlocation_formatter',
'settings' => [],
],
],
];
$info['schema__license'] = [
'field_name' => 'schema__license',
'entity_type' => 'TripalEntity',
'bundle' => $bundle->name,
'label' => 'License',
'description' => 'The license for the file.',
'required' => TRUE,
'settings' => [
'auto_attach' => TRUE,
'chado_table' => 'file_license',
'chado_column' => 'file_license_id',
'base_table' => 'file',
'term_accession' => 'license',
'term_vocabulary' => 'schema',
'term_name' => 'license',
],
'widget' => [
'type' => 'schema__license_widget',
'settings' => [
'display_label' => 1,
],
],
'display' => [
'default' => [
'label' => 'inline',
'type' => 'schema__license_formatter',
'settings' => [],
],
],
];
$info['sio__references_file'] = [
'field_name' => 'sio__references_file',
'entity_type' => 'TripalEntity',
'bundle' => $bundle->name,
'label' => 'References',
'description' => 'Content that references this file.',
'required' => FALSE,
'settings' => [
'auto_attach' => FALSE,
'chado_table' => 'file',
'chado_column' => 'file_id',
'base_table' => 'file',
'term_accession' => '000631',
'term_vocabulary' => 'SIO',
'term_name' => 'references',
],
'widget' => [
'type' => 'sio__references_file_widget',
'settings' => [
'display_label' => 1,
],
],
'display' => [
'default' => [
'label' => 'inline',
'type' => 'sio__references_file_formatter',
'settings' => [],
],
],
];
}
// If a _file linker table exists for the base data table.
if (chado_table_exists($chado_bundle->data_table . '_file')) {
$base_table = $chado_bundle->data_table;
$chado_table = $chado_bundle->data_table . '_file';
$info['sio__file'] = [
'field_name' => 'sio__file',
'entity_type' => 'TripalEntity',
'bundle' => $bundle->name,
'label' => 'File',
'description' => 'A file.',
'required' => FALSE,
'settings' => [
'auto_attach' => FALSE,
'chado_table' => $chado_table,
'chado_column' => $chado_table . '_id',
'base_table' => $base_table,
'term_accession' => '000396',
'term_vocabulary' => 'SIO',
'term_name' => 'file',
],
'widget' => [
'type' => 'sio__file_widget',
'settings' => [
'display_label' => 1,
],
],
'display' => [
'default' => [
'label' => 'inline',
'type' => 'sio__file_formatter',
'settings' => [],
],
],
];
}
return $info;
}
/**
* Implements hook_bundle_fields_info_alter().
*/
function tripal_file_bundle_fields_info_alter(&$info, $bundle, $term) {
}
/**
* Implements hook_bundle_fields_info_alter().
*/
function tripal_file_bundle_instances_info_alter(&$info, $bundle, $term) {
if (!$info) {
return;
}
if (array_key_exists('file_contact', $info)) {
$info['file_contact']['label'] = 'File Source';
}
// Fields for the File content type.
if ($bundle->accession == 'SIO:000396') {
$info['schema__name']['widget']['type'] = 'text_textfield';
$info['schema__name']['settings']['text_processing'] = '0';
}
// Fields for the License content type.
if ($bundle->accession == 'schema:license') {
// We don't want the URL to be a textfield:
$info['data__uri']['label'] = 'URI';
$info['data__uri']['widget']['type'] = 'text_textfield';
$info['data__uri']['settings']['text_processing'] = '0';
}
}
/**
* Implements hook_tripal_default_title_format().
*
* Overrides the default titles.
*/
function tripal_file_tripal_default_title_format($bundle, $available_tokens) {
$format = [];
$table = $bundle->data_table;
if ($table == 'file') {
$format[] = [
'format' => '[schema__name]',
'weight' => -5,
];
}
if ($table == 'license') {
$format[] = [
'format' => '[schema__name]',
'weight' => -5,
];
}
return $format;
}