Révision 4543c6c7
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/sites/all/modules/addthis/addthis.module | ||
---|---|---|
5 | 5 |
* in a separate AddThis-class to keep the .module-file clean. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
module_load_include('inc', 'addthis', 'includes/addthis.block'); |
|
8 |
if (module_exists('block')) { |
|
9 |
module_load_include('inc', 'addthis', 'includes/addthis.block'); |
|
10 |
} |
|
9 | 11 |
module_load_include('inc', 'addthis', 'includes/addthis.field'); |
10 | 12 |
|
11 | 13 |
/** |
... | ... | |
97 | 99 |
); |
98 | 100 |
} |
99 | 101 |
|
100 |
/** |
|
101 |
* Implements hook_page_alter(). |
|
102 |
*/ |
|
103 |
function addthis_page_alter(&$page) { |
|
104 |
AddThis::getInstance()->addWidgetJs(); |
|
105 |
AddThis::getInstance()->addConfigurationOptionsJs(); |
|
106 |
} |
|
107 |
|
|
108 | 102 |
/** |
109 | 103 |
* Implements hook_form_FORM_ID_alter(). |
110 | 104 |
* |
... | ... | |
201 | 195 |
$output .= '</' . $element['#tag'] . ">\n"; |
202 | 196 |
return $output; |
203 | 197 |
} |
198 |
|
|
199 |
/** |
|
200 |
* Create a addthis settings form. |
|
201 |
*/ |
|
202 |
function _addthis_settings_form($form = array(), &$form_state, $display_type = NULL, $display_settings = NULL) { |
|
203 |
// Toggle variables |
|
204 |
$no_js = FALSE; |
|
205 |
|
|
206 |
|
|
207 |
// Default display type if not set in the parameters. |
|
208 |
$display_type = (isset($display_type)) ? $display_type : 'addthis_disabled'; |
|
209 |
// Load setting type from the form_state. |
|
210 |
if (isset($form_state['values']['addthis_settings']['type'])) { |
|
211 |
$display_type = $form_state['values']['addthis_settings']['type']; |
|
212 |
} |
|
213 |
|
|
214 |
// Container used as the replace for ajax. |
|
215 |
$form['#type'] = 'container'; |
|
216 |
$form['#attributes'] = array(); |
|
217 |
$form['#id'] = 'addthis_settings'; |
|
218 |
|
|
219 |
// The list of formatters. |
|
220 |
$formatter_options = AddThis::getInstance()->getDisplayTypes(); |
|
221 |
$form['type'] = array( |
|
222 |
'#type' => 'select', |
|
223 |
'#title' => t('Formatter for @title', array('@title' => 'AddThis block')), |
|
224 |
'#title_display' => 'invisible', |
|
225 |
'#options' => $formatter_options, |
|
226 |
'#default_value' => $display_type, |
|
227 |
'#parents' => array('addthis_settings', 'type'), |
|
228 |
'#attributes' => array('class' => array('addthis-display-type')), |
|
229 |
'#ajax' => array( |
|
230 |
'callback' => '_addthis_settings_form_submit_callback', |
|
231 |
'wrapper' => 'addthis_settings', |
|
232 |
'name' => 'switch_display', |
|
233 |
'event' => 'change', |
|
234 |
) |
|
235 |
); |
|
236 |
|
|
237 |
if ($no_js) { |
|
238 |
$form['choose'] = array( |
|
239 |
'#type' => 'submit', |
|
240 |
'#name' => 'Switch display', |
|
241 |
'#value' => 'Switch display', |
|
242 |
'#op' => 'switch_display', |
|
243 |
'#id' => 'switch-display', |
|
244 |
'#submit' => array('_addthis_settings_form_submit'), |
|
245 |
); |
|
246 |
} |
|
247 |
|
|
248 |
// Formatter settings. |
|
249 |
|
|
250 |
// Check the currently selected formatter, and merge persisted values for |
|
251 |
// formatter settings. |
|
252 |
$formatter_type = $display_type; |
|
253 |
|
|
254 |
// Get the settings if set. |
|
255 |
$settings = $display_settings; |
|
256 |
$formatter_settings = field_info_formatter_settings($formatter_type); |
|
257 |
$settings += $formatter_settings; |
|
258 |
|
|
259 |
$field = array(); |
|
260 |
$instance = array(); |
|
261 |
$view_mode = 'block'; |
|
262 |
|
|
263 |
$instance['display'][$view_mode]['type'] = $formatter_type; |
|
264 |
$formatter = field_info_formatter_types($formatter_type); |
|
265 |
$instance['display'][$view_mode]['module'] = $formatter['module']; |
|
266 |
$instance['display'][$view_mode]['settings'] = $settings; |
|
267 |
|
|
268 |
$settings_form = array(); |
|
269 |
$function = $formatter['module'] . '_field_formatter_settings_form'; |
|
270 |
if (function_exists($function)) { |
|
271 |
$settings_form = $function($field, $instance, $view_mode, $form, $form_state); |
|
272 |
$settings_form['#tree'] = TRUE; |
|
273 |
$settings_form['#parents'] = array('addthis_settings', 'settings'); |
|
274 |
} |
|
275 |
|
|
276 |
$form['settings'] = $settings_form; |
|
277 |
|
|
278 |
return $form; |
|
279 |
} |
|
280 |
|
|
281 |
function _addthis_settings_form_submit($form, &$form_state) { |
|
282 |
$form_state['rebuild'] = TRUE; |
|
283 |
} |
|
284 |
|
|
285 |
function _addthis_settings_form_submit_callback($form, &$form_state) { |
|
286 |
$form_state['rebuild'] = TRUE; |
|
287 |
return $form['addthis_settings']['form']; |
|
288 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules