-
Notifications
You must be signed in to change notification settings - Fork 1
/
ting_null_covers.module
executable file
·83 lines (71 loc) · 2.24 KB
/
ting_null_covers.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
<?php
/**
* @file
* Module which allows control of how missing item covers are displayed.
*/
/**
* Implements hook_menu().
*/
function ting_null_covers_menu() {
$menu = array();
$menu['admin/config/ting/covers/null'] = array(
'title' => 'Empty covers',
'description' => 'Configure how empty covers are displayed',
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_null_covers_admin_form'),
'access arguments' => array('null covers display'),
'file' => 'ting_null_covers.admin.inc',
'type' => MENU_LOCAL_TASK,
);
return $menu;
}
/**
* Implements hook_permission().
*/
function ting_null_covers_permission() {
$perm = array();
$perm['null covers display'] = array(
'title' => t('Manage empty covers'),
'description' => t('Control how the empty covers are displayed.'),
);
return $perm;
}
/**
* Implements hook_entity_view().
*
* We cannot oversee if the item has a cover or not, so a request to cover
* service is required here.
*/
function ting_null_covers_entity_view($entity, $entity_type, $view_mode, $langcode) {
if (!variable_get('ting_null_covers_hide', FALSE)) {
return;
}
elseif ($entity_type == 'ting_object' && ($view_mode == 'collection_list' || $view_mode == 'teaser')) {
drupal_add_css(drupal_get_path('module', 'ting_null_covers') . '/css/ting_null_covers.styles.css', 'file');
$localId = $entity->localId;
$unset_image = FALSE;
$path = ting_covers_object_path($localId);
// In case when covers were requested earlier and were not found.
if (cache_get('ting_covers:' . $localId)) {
$unset_image = TRUE;
}
// In case when cover is missing, check if it actually is missing
// at ADDI service.
elseif (!file_exists($path)) {
$service = new AdditionalInformationService(
variable_get('addi_wsdl_url'),
variable_get('addi_username'),
variable_get('addi_group'),
variable_get('addi_password')
);
$additional_informations = $service->getByFaustNumber($localId);
$ai = $additional_informations[$localId];
if (!$ai->detailUrl && !$ai->thumbnailUrl) {
$unset_image = TRUE;
}
}
if ($unset_image) {
unset($entity->content['ting_cover']);
}
}
}