This repository has been archived by the owner on May 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kkb_wayfinder.module
66 lines (58 loc) · 1.95 KB
/
kkb_wayfinder.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
<?php
/**
* @file
* Adds button to material to find it physically at the library.
*/
/**
* Implements hook_menu().
*/
function kkb_wayfinder_menu() {
$items['admin/config/ding/wayfinder'] = array(
'title' => 'Wayfinder settings',
'description' => 'Manage wayfinder branch mapping.',
'page callback' => 'drupal_get_form',
'page arguments' => array('kkb_wayfinder_admin_form'),
'access arguments' => array('administer ding provider'),
'file' => 'kkb_wayfinder.admin.inc',
);
return $items;
}
/**
* Implements hook_ding_entity_buttons().
*/
function kkb_wayfinder_ding_entity_buttons($type, $entity) {
if ($type == 'ding_entity') {
$return = array();
$branches = variable_get('kkb_wayfinder_branches', array());
$availability = ding_availability_holdings(array($entity->localId));
$options = array();
foreach ($availability[$entity->localId]['holdings'] as $holding) {
if ($holding['available_count'] > 0 && isset($branches[drupal_strtolower($holding['placement'][0])])) {
$options[] = array(
'custom' => array(
'title' => $holding['placement'][0],
'href' => '#',
'attributes' => array(
'class' => array(),
'data-wayfinder-faust' => $entity->localId,
'data-wayfinder-branch' => $branches[drupal_strtolower($holding['placement'][0])],
),
),
);
}
}
if ($options) {
// We have to use drupal_add_js() because #attached on the
// ding_list_add_button is ignored for some reason.
drupal_add_js(drupal_get_path('module', 'kkb_wayfinder') . '/js/kkb_wayfinder.js');
drupal_add_js('https://os2.wayfindingkkb.dk/embed/v1/wayfinding.js', 'external');
$return[] = array(
'#theme' => 'ding_list_add_button',
'#title' => t('See on map'),
'#value' => $entity->ding_entity_id,
'#options' => $options,
);
}
return $return;
}
}