-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathting_covers.field.inc
117 lines (104 loc) · 2.91 KB
/
ting_covers.field.inc
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
<?php
/**
* @file
* Field hook implementations.
*/
/**
* Implements hook_field_info().
*/
function ting_covers_field_info() {
return array(
'ting_cover' => array(
'label' => t('Ting cover'),
'description' => t('Cover image from the ADDI service, if any.'),
'default_widget' => 'hidden',
'default_formatter' => 'ting_cover_default',
'no_ui' => TRUE,
),
);
}
/**
* Implements hook_field_load().
*/
function ting_covers_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
foreach ($entities as $id => $entity) {
$items[$id][0] = array(
'local_id' => $entity->localId,
);
}
}
/**
* Implements hook_widget_info_alter().
*/
function ting_covers_widget_info_alter(&$info) {
if (isset($info['hidden'])) {
$info['hidden']['field types'][] = 'ting_cover';
}
}
/**
* Implements hook_field_formatter_info().
*/
function ting_covers_field_formatter_info() {
return array(
'ting_cover_default' => array(
'label' => t('Default'),
'field types' => array('ting_cover'),
'settings' => array(
'image_style' => 'medium',
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function ting_covers_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$element = array();
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function ting_covers_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
if (isset($image_styles[$settings['image_style']])) {
$summary = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
}
else {
$summary = t('Original image');
}
return $summary;
}
/**
* Implements hook_field_formatter_view().
*/
function ting_covers_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'ting_object_cover',
'#object' => $entity,
'#image_style' => $display['settings']['image_style'],
'#attached' => array(
'js' => array(drupal_get_path('module', 'ting_covers') . '/js/ting-covers.js'),
),
);
}
return $element;
}