-
Notifications
You must be signed in to change notification settings - Fork 0
/
ting_visual_relation.module
354 lines (332 loc) · 11.7 KB
/
ting_visual_relation.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
<?php
/**
* @file
*
* Module file for the Ting visual relation module.
*/
// Include our feature override.
include_once 'ting_visual_relation.features.inc';
/**
* Implements hook_ctools_plugin_directory().
*
* Tells panels where to find plugins.
*/
function ting_visual_relation_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && !empty($plugin)) {
return "plugins/$plugin";
}
}
/**
* Implements hook_menu().
*/
function ting_visual_relation_menu() {
$items = array();
// Callbacks
$common = array(
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ting_visual_relation.pages.inc',
);
$items['ting-visual-relation/get-ting-object'] = array(
'title' => 'Get ting object',
'page callback' => 'ting_visual_relation_get_ting_object',
) + $common;
$items['ting-visual-relation/get-ting-collection'] = array(
'title' => 'Get ting collection',
'page callback' => 'ting_visual_relation_get_ting_collection',
) + $common;
$items['ting-visual-relation/get-recommendations'] = array(
'title' => 'Get recommendations',
'page callback' => 'ting_visual_relation_get_recommendations',
) + $common;
$items['ting-visual-relation/get-availability'] = array(
'title' => 'Get availability',
'page callback' => 'ting_visual_relation_get_availability',
) + $common;
$items['ting-visual-relation/get-search-result'] = array(
'title' => 'Get search result',
'page callback' => 'ting_visual_relation_get_search_result',
) + $common;
$items['ting-visual-relation/get-slideshow-settings'] = array(
'title' => 'Get slideshow settings',
'page callback' => 'ting_visual_relation_get_slideshow_settings',
) + $common;
$items['ting-visual-relation/send-bookmark-mail'] = array(
'title' => 'Send mail with bookmarks',
'page callback' => 'ting_visual_relation_send_bookmark_mail',
) + $common;
// Administration
$common = array(
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'file' => 'ting_visual_relation.admin.inc',
);
$items['admin/config/ting/ting-visual-relation'] = array(
'title' => 'Ting visual relation',
'description' => 'Manage settings for the Ting visual relation module',
'page arguments' => array('ting_visual_relation_settings_form'),
) + $common;
$items['admin/config/ting/ting-visual-relation/settings'] = array(
'title' => 'Settings',
'description' => 'Manage basic settings for the Ting visual relation module',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/ting/ting-visual-relation/app-settings'] = array(
'title' => 'App settings',
'description' => 'Manage settings for the Visual relation app.',
'page arguments' => array('ting_visual_relation_app_settings_form'),
'type' => MENU_LOCAL_TASK,
) + $common;
$items['admin/config/ting/ting-visual-relation/app-settings/add'] = array(
'title' => 'Add slide',
'description' => 'Add a slide to the Visual relation app.',
'page arguments' => array('ting_visual_relation_add_slide_form'),
'type' => MENU_LOCAL_ACTION,
) + $common;
$items['admin/config/ting/ting-visual-relation/app-settings/%/edit'] = array(
'title' => 'Edit slide',
'description' => 'Edit a slide from the Visual relation app slideshow',
'page arguments' => array('ting_visual_relation_edit_slide_form', 5),
) + $common;
$items['admin/config/ting/ting-visual-relation/app-settings/%/delete'] = array(
'title' => 'Delete slide',
'description' => 'Delete a slide from the Visual relation app slideshow',
'page arguments' => array('ting_visual_relation_delete_slide_confirm_form', 5),
) + $common;
return $items;
}
/**
* Implements hook_theme().
*/
function ting_visual_relation_theme() {
return array(
'ting_visual_relation_activation_area' => array(
'template' => 'ting-visual-relation-activation-area',
'variables' => array(
// Array with activators to go in this area.
'activators' => array(),
),
'file' => 'ting_visual_relation.theme.inc',
),
'ting_visual_relation_activator' => array(
'variables' => array(
// The type of relationbrowser (external, circular or struct)
'type' => NULL,
// The text to go on the button
'text' => NULL,
// Will only be set for external- and circular-type relation browsers
'object' => NULL,
// Will only be set for the search-type relation browser
'search' => NULL,
),
'file' => 'ting_visual_relation.theme.inc',
),
'ting_visual_relation_app_settings_form' => array(
'render element' => 'form',
'file' => 'ting_visual_relation.admin.inc',
),
);
}
/**
* Implements hook_ding_provider_user().
*/
function ting_visual_relation_ding_provider_user() {
return array(
'availability' => array(
'required' => TRUE,
'install time setup' => TRUE,
),
);
}
/**
* Implements hook_forms()
*/
function ting_visual_relation_forms() {
$forms = array();
$forms['ting_visual_relation_add_slide_form'] = array(
'callback' => 'ting_visual_relation_slide_form',
);
$forms['ting_visual_relation_edit_slide_form'] = array(
'callback' => 'ting_visual_relation_slide_form',
);
return $forms;
}
/**
* Implements hook_mail().
*/
function ting_visual_relation_mail($key, &$message, $params) {
switch ($key) {
case 'ting_visual_relation_bookmark_mail':
$message['id'] = $key;
$message['subject'] = t('Bookmark mail sent from Visual relation application');
$message['body'][] = '<h2>' . t('The materails you bookmarked in the Visual relation application today') . '</h2>';
$message['body'][] = '<p>' . t('Each title is a link to the materail on our website.') . '</p>';
$message['body'][] = '<p>' . t('On the website you can view further information about the materail, bookmark to your pesonal account and/or reserve it for pick up at the library.') . '</p>';
$message['body'][] = $params['message'];
break;
}
}
/**
* Implements hook_mail_alter().
*
* Adds headers to allow HTML mails to be sent from this module.
* @see https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_mail_alter/7
*/
function ting_visual_relation_mail_alter(&$message) {
if ($message['id'] == 'ting_visual_relation_bookmark_mail') {
$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=iso-8859-1; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
);
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
}
}
/**
* Implements hook_field_info().
*
* The field is configured as a virtual field with features without using
* hook_ding_entity_field(). See:
* ting_visual_relation.features.field_base.inc
* ting_visual_relation.features.field_instance.inc
*/
function ting_visual_relation_field_info() {
return array(
'ting_visual_relations' => array(
'label' => t('Ting visual relations'),
'description' => t('A field type that adds an acitivator for a visual relation browser.'),
'default_widget' => 'hidden',
'default_formatter' => 'ting_visual_relations_default',
'no_ui' => TRUE,
),
);
}
/**
* Implements hook_field_load().
*
* Populate the items array preventing the Field API marking it as empty.
*/
function ting_visual_relation_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
foreach ($entities as $id => $entity) {
$items[$id][0] = array('id' => $id);
}
}
/**
* Implements hook_widget_info_alter().
*
* Adds our field type to the list of supported fields, for the 'hidden' field
* widget defined in core.
*/
function ting_visual_relation_widget_info_alter(&$info) {
if (isset($info['hidden'])) {
$info['hidden']['field types'][] = 'ting_visual_relations';
}
}
/**
* Implements hook_field_formatter_info().
*/
function ting_visual_relation_field_formatter_info() {
return array(
'ting_visual_relations_default' => array(
'label' => t('Default'),
'field types' => array(
'ting_visual_relations',
),
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function ting_visual_relation_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$d3 = libraries_load('d3');
// No need to show field if D3 is not installed proberly.
if (!empty($d3['installed']) && version_compare($d3['version'], '3.0') > 0) {
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'ting_visual_relation_activation_area',
'#activators' => array(),
);
$element[$delta]['#activators'][] = array(
'#theme' => 'ting_visual_relation_activator',
'#type' => 'external',
'#text' => t('Browse relations'),
'#object' => $entity,
);
$element[$delta]['#activators'][] = array(
'#theme' => 'ting_visual_relation_activator',
'#type' => 'circular',
'#text' => t('Recommendations'),
'#object' => $entity,
);
}
ting_visual_relation_prepare_render_array($element);
}
else {
drupal_set_message(t('The visual relations field needs D3 version 3.0+ library installed. Go to the <a href="@status">Status Page</a> for more information', array(
'@status' => 'admin/config/status',
)), 'error');
}
return $element;
}
/**
* Implements hook_process_ting_object().
*
* With certain versions of features the feature-override fails to add our
* fields to the right-column on ting-objects. So we implement this hook to
* make sure the field is in the right place and is not destroying the order
* of the other fields.
* This bug has been found in version 7.x-2.0-beta2 of features.
*/
function ting_visual_relation_process_ting_object(&$vars) {
$content = &$vars['content'];
// If 'field_ting_visual_relations' is set the feature failed to place our
// field on install.
if (isset($content['field_ting_visual_relations']) && isset($content['ting-object']['content']['right_column'])) {
$field['field_ting_visual_relations'] = $content['field_ting_visual_relations'];
unset($content['field_ting_visual_relations']);
$content['ting-object']['content']['right_column'] += $field;
}
}
/**
* Prepares a render-array for a Ting visual relation activation area with the
* needed Javascript and CSS.
*/
function ting_visual_relation_prepare_render_array(&$render_array) {
// Pass the API- and log-URL to javascript as a setting.
global $base_url;
$api_url = $base_url . '/ting-visual-relation';
$log_url = '//relvis.solsort.com/_relvis_log.js';
$render_array['#attached']['js'][] = array(
'data' => array(
'tingVisualRelation' => array(
'apiUrl' => $api_url,
'logUrl' => $log_url,
),
),
'type' => 'setting',
);
$path = drupal_get_path('module', 'ting_visual_relation');
$render_array['#attached']['js'][] = $path . '/js/ting_visual_relation.relvis.min.js';
$render_array['#attached']['js'][] = $path . '/js/ting_visual_relation.js';
$render_array['#attached']['css'][] = $path . '/css/ting_visual_relation.base.css';
$render_array['#attached']['css'][] = $path . '/css/ting_visual_relation.theme.css';
}
/**
* Wrapper function to hold the different types of relation browsers.
*/
function ting_visual_relation_types() {
return array(
'external' => t('External browser'),
'circular' => t('Circular browser'),
// Search would probably be a better machine-name for Search browser, but
// the relation browser HTML5 component uses structural, so we stick with
// this terminology for now.
'structural' => t('Search browser'),
);
}