-
Notifications
You must be signed in to change notification settings - Fork 2
/
trpfancy_fields.module
95 lines (82 loc) · 2.88 KB
/
trpfancy_fields.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
<?php
/**
* @file
*/
// Includes all non-class field functions.
include('includes/trpfancy_fields.fields.inc');
include('includes/TripalFields/data__identifier/data__identifier_widget.inc');
/**
* Add all terms needed for our fields
* @todo move this into an install file.
*/
function trpfancy_fields_add_field_terms() {
$terms = array(
array(
'cv_name' => 'local',
'id' => 'local:quick_search',
'name' => 'Quick Search',
'definition' => 'Provide a quick search on entity pages which submits/redirects to a full search.',
),
array(
'cv_name' => 'local',
'id' => 'local:gbrowse_image',
'name' => 'Gbrowse Image',
'definition' => 'A GBrowse image of a feature alignment to another sequence',
)
);
// Now add each term.
foreach ($terms as $term) {
tripal_insert_cvterm($term);
}
}
/**
* Implements hook_menu().
*/
function trpfancy_fields_menu() {
// Menu home.
$items['admin/tripal/extension/trpfancyfields'] = array(
'title' => 'Tripal Fancy Fields',
'description' => 'Tripal Fancy Fields.',
'access arguments' => array('administer tripal'),
);
// ADMISTRATIVE PAGE:
// A page for changing prefix used to generate uniquename in Identifier field.
// NOTE: this variable is used by data__identifier field.
$items['admin/tripal/extension/trpfancyfields/prefix'] = array(
'title' => 'Configure Data Identifier Prefix',
'description' => t('Provides interface for configuring prefix used to auto-generate uniquename/identifier.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('trpfancy_fields_config'),
'access arguments' => array('administer tripal'),
'type' => MENU_NORMAL_ITEM,
'weight' => 1,
);
return $items;
}
/**
* Function callback:
* Construct form interface to update prefix configuration.
*/
function trpfancy_fields_config($form, &$form_state) {
// System variable used to store prefix value:
// NOTE: this variable is used by data__identifier field.
$cur_prefix = variable_get('trpfancy_field_identifier_prefix');
// Show an example of the prefix in action.
$form['preview_prefix'] = array(
'#type' => 'markup',
'#markup' => 'Example (Prefix + ID#): <br />
<div style="font-family: courier, serif; font-size: 2em; margin: 5px 0 20px 0; border: 1px solid #CCCCCC; padding: 10px; display: inline-block;">'
. $cur_prefix . '<span style="color: #666666">' . mt_rand(7777, 9999) . '</span></div>',
);
// Prefix field.
$form['trpfancy_field_identifier_prefix'] = array(
'#type' => 'textfield',
'#title' => t('Prefix'),
'#description' => t('Prefix used to generate uniquename for Identifier field.'),
'#default_value' => $cur_prefix,
'#required' => TRUE,
);
// This will add a save button to this form, thus
// no hook_submit nor hook_validate is required.
return system_settings_form($form);
}