1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Defines field implementations.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_field_formatter_info().
|
10
|
*/
|
11
|
function addthis_displays_field_formatter_info() {
|
12
|
$formatters = array();
|
13
|
|
14
|
$formatters['addthis_basic_toolbox'] = array(
|
15
|
'label' => t('Basic Toolbox'),
|
16
|
'field types' => array(AddThis::FIELD_TYPE),
|
17
|
'settings' => array(
|
18
|
'share_services' => 'facebook,twitter',
|
19
|
'buttons_size' => 'addthis_16x16_style',
|
20
|
'counter_orientation' => 'horizontal',
|
21
|
'extra_css' => '',
|
22
|
),
|
23
|
);
|
24
|
$formatters['addthis_basic_button'] = array(
|
25
|
'label' => t('Basic Button'),
|
26
|
'field types' => array(AddThis::FIELD_TYPE),
|
27
|
'settings' => array(
|
28
|
'button_size' => 'small',
|
29
|
'extra_css' => '',
|
30
|
),
|
31
|
);
|
32
|
return $formatters;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* Implementss hook_field_formatter_settings_form().
|
37
|
*/
|
38
|
function addthis_displays_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
39
|
$display = $instance['display'][$view_mode];
|
40
|
$settings = $display['settings'];
|
41
|
$element = array();
|
42
|
|
43
|
switch ($display['type']) {
|
44
|
case 'addthis_basic_toolbox':
|
45
|
$element['share_services'] = array(
|
46
|
'#title' => t('Services'),
|
47
|
'#type' => 'textfield',
|
48
|
'#size' => 80,
|
49
|
'#default_value' => $settings['share_services'],
|
50
|
'#required' => TRUE,
|
51
|
'#element_validate' => array('_addthis_display_element_validate_services'),
|
52
|
'#description' =>
|
53
|
t('Specify the names of the sharing services and seperate them with a , (comma). <a href="http://www.addthis.com/services/list" target="_blank">The names on this list are valid.</a>') .
|
54
|
t('Elements that are available but not ont the services list are (!services).',
|
55
|
array('!services' => 'bubble_style, pill_style, tweet, facebook_send, twitter_follow_native, google_plusone, stumbleupon_badge, counter_* (several supported services), linkedin_counter')
|
56
|
),
|
57
|
);
|
58
|
$element['buttons_size'] = array(
|
59
|
'#title' => t('Buttons size'),
|
60
|
'#type' => 'select',
|
61
|
'#default_value' => $settings['buttons_size'],
|
62
|
'#options' => array(
|
63
|
AddThis::CSS_16x16 => t('Small (16x16)'),
|
64
|
AddThis::CSS_32x32 => t('Big (32x32)'),
|
65
|
),
|
66
|
);
|
67
|
$element['counter_orientation'] = array(
|
68
|
'#title' => t('Counter orientation'),
|
69
|
'#description' => t('Specify the way service counters are oriented.'),
|
70
|
'#type' => 'select',
|
71
|
'#default_value' => $settings['counter_orientation'],
|
72
|
'#options' => array(
|
73
|
'horizontal' => t('Horizontal'),
|
74
|
'vertical' => t('Vertical'),
|
75
|
)
|
76
|
);
|
77
|
$element['extra_css'] = array(
|
78
|
'#title' => t('Extra CSS declaration'),
|
79
|
'#type' => 'textfield',
|
80
|
'#size' => 40,
|
81
|
'#default_value' => $settings['extra_css'],
|
82
|
'#description' => t('Specify extra CSS classes to apply to the toolbox'),
|
83
|
);
|
84
|
break;
|
85
|
case 'addthis_basic_button':
|
86
|
$element['button_size'] = array(
|
87
|
'#title' => t('Image'),
|
88
|
'#type' => 'select',
|
89
|
'#default_value' => $settings['button_size'],
|
90
|
'#options' => array(
|
91
|
'small' => t('Small'),
|
92
|
'big' => t('Big'),
|
93
|
),
|
94
|
);
|
95
|
$element['extra_css'] = array(
|
96
|
'#title' => t('Extra CSS declaration'),
|
97
|
'#type' => 'textfield',
|
98
|
'#size' => 40,
|
99
|
'#default_value' => $settings['extra_css'],
|
100
|
'#description' => t('Specify extra CSS classes to apply to the button'),
|
101
|
);
|
102
|
break;
|
103
|
}
|
104
|
|
105
|
return $element;
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Validate the services text field to validate if services are correct.
|
110
|
*/
|
111
|
function _addthis_display_element_validate_services($element, &$form_state, $form) {
|
112
|
$bad = FALSE;
|
113
|
|
114
|
$services = trim($element['#value']);
|
115
|
$services = str_replace(' ', '', $services);
|
116
|
|
117
|
if (!preg_match('/^[a-z\_\,0-9]+$/', $services)) {
|
118
|
$bad = TRUE;
|
119
|
}
|
120
|
// @todo Validate the service names against AddThis.com. Give a notice when there are bad names.
|
121
|
|
122
|
// Return error.
|
123
|
if ($bad) {
|
124
|
form_error($element, t('The declared services are incorrect or nonexistent.'));
|
125
|
}
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Implements hook_field_formatter_settings_summary().
|
130
|
*/
|
131
|
function addthis_displays_field_formatter_settings_summary($field, $instance, $view_mode) {
|
132
|
$view = $instance['display'][$view_mode];
|
133
|
$info = '';
|
134
|
switch ($view['type']) {
|
135
|
case 'addthis_basic_toolbox':
|
136
|
$settings = $view['settings'];
|
137
|
|
138
|
$services = trim($settings['share_services']);
|
139
|
$services = str_replace(' ', '', $services);
|
140
|
$services = '<b>' . implode(', ', explode(',', $services)) . '</b>';
|
141
|
|
142
|
$info = t('Toolbox with the following services: !services', array('!services' => $services));
|
143
|
break;
|
144
|
|
145
|
case 'addthis_basic_button':
|
146
|
$settings = $view['settings'];
|
147
|
|
148
|
$size = '<b>' . $settings['button_size'] . '</b>';
|
149
|
$info = t('Basic button size: !size', array('!size' => $size));
|
150
|
break;
|
151
|
}
|
152
|
|
153
|
return $info;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Implements hook_field_formatter_view().
|
158
|
*/
|
159
|
function addthis_displays_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
160
|
// We use the helper function addthis_render_formatter_view with literally all the arguments.
|
161
|
return addthis_render_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
|
162
|
}
|