1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Block related hook implementations for the AddThis-module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_block_info().
|
10 |
|
|
*/
|
11 |
|
|
function addthis_block_info() {
|
12 |
|
|
$block_info = array();
|
13 |
|
|
$block_info[AddThis::BLOCK_NAME] = array(
|
14 |
|
|
'info' => t('AddThis'),
|
15 |
|
|
'cache' => DRUPAL_NO_CACHE,
|
16 |
|
|
);
|
17 |
|
|
return $block_info;
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Implements hook_block_view().
|
22 |
|
|
*
|
23 |
|
|
* #block key allows alter hooks to react on this information. Someone might
|
24 |
|
|
* want to change this specific display.
|
25 |
|
|
*/
|
26 |
|
|
function addthis_block_view($block_name = '') {
|
27 |
4543c6c7
|
Assos Assos
|
|
28 |
85ad3d82
|
Assos Assos
|
if ($block_name == AddThis::BLOCK_NAME) {
|
29 |
4543c6c7
|
Assos Assos
|
|
30 |
85ad3d82
|
Assos Assos
|
$widget_type = AddThis::getInstance()->getBlockDisplayType();
|
31 |
4543c6c7
|
Assos Assos
|
$widget_settings = AddThis::getInstance()->getBlockDisplaySettings();
|
32 |
|
|
|
33 |
|
|
$block_options = array(
|
34 |
|
|
'#block' => AddThis::BLOCK_NAME,
|
35 |
|
|
'#display' => array(
|
36 |
|
|
'settings' => $widget_settings,
|
37 |
|
|
)
|
38 |
|
|
);
|
39 |
|
|
|
40 |
|
|
$markup = AddThis::getInstance()->getDisplayMarkup($widget_type, $block_options);
|
41 |
85ad3d82
|
Assos Assos
|
return array(
|
42 |
|
|
'subject' => '',
|
43 |
|
|
'content' => $markup,
|
44 |
|
|
);
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
|
|
* Implements hook_block_configure().
|
50 |
|
|
*/
|
51 |
|
|
function addthis_block_configure($delta = '') {
|
52 |
4543c6c7
|
Assos Assos
|
AddThis::getInstance()->includeWidgetJs();
|
53 |
|
|
|
54 |
|
|
return array();
|
55 |
85ad3d82
|
Assos Assos
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Implements hook_block_save().
|
59 |
|
|
*/
|
60 |
|
|
function addthis_block_save($delta = '', $edit = array()) {
|
61 |
4543c6c7
|
Assos Assos
|
variable_set(AddThis::BLOCK_WIDGET_TYPE_KEY, $edit['addthis_settings']['type']);
|
62 |
|
|
variable_set(AddThis::BLOCK_WIDGET_SETTINGS_KEY, $edit['addthis_settings']['settings']);
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Callback submit.
|
67 |
|
|
*/
|
68 |
|
|
function _addthis_settings_form_block_submit($form, &$form_state) {
|
69 |
|
|
$form_state['rebuild'] = TRUE;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Callback to return ajax replace part.
|
74 |
|
|
*/
|
75 |
|
|
function _addthis_settings_form_block_submit_callback($form, &$form_state) {
|
76 |
|
|
return $form['settings']['addthis_settings']['form'];
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Implements hook_form_FORM_ID_alter().
|
81 |
|
|
*/
|
82 |
|
|
function addthis_form_block_admin_configure_alter(&$form, &$form_state) {
|
83 |
|
|
|
84 |
|
|
if ($form['module']['#value'] == 'addthis' && $form['delta']['#value'] == 'addthis_block') {
|
85 |
|
|
form_load_include($form_state, 'inc', 'addthis', 'addthis.block');
|
86 |
|
|
$form['#cache'] = TRUE;
|
87 |
|
|
|
88 |
|
|
$form['settings']['addthis_settings'] = array(
|
89 |
|
|
'#type' => 'fieldset',
|
90 |
|
|
'#title' => 'Display settings',
|
91 |
|
|
);
|
92 |
|
|
|
93 |
|
|
// Retrieve settings.
|
94 |
|
|
$addthis_settings['type'] = AddThis::getInstance()->getBlockDisplayType();
|
95 |
|
|
$addthis_settings['settings'] = AddThis::getInstance()->getBlockDisplaySettings();
|
96 |
|
|
|
97 |
|
|
// Create a addthis settings form based on the available configuration.
|
98 |
|
|
$element = _addthis_settings_form(
|
99 |
|
|
isset($form['addthis_settings']['form']) ? $form['addthis_settings']['form'] : array(),
|
100 |
|
|
$form_state,
|
101 |
|
|
isset($addthis_settings['type']) ? $addthis_settings['type'] : NULL,
|
102 |
|
|
isset($addthis_settings['settings']) ? $addthis_settings['settings'] : NULL
|
103 |
|
|
);
|
104 |
|
|
|
105 |
|
|
// Change the submit and callback because our handling is different and the
|
106 |
|
|
// form structure is different form the default implementation.
|
107 |
|
|
$element['type']['#submit'] = array('_addthis_settings_form_block_submit');
|
108 |
|
|
$element['type']['#ajax']['callback'] = '_addthis_settings_form_block_submit_callback';
|
109 |
|
|
$form['settings']['addthis_settings']['form'] = $element;
|
110 |
|
|
|
111 |
|
|
array_unshift($form['#submit'], '_addthis_settings_form_block_submit');
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
return $form;
|
115 |
85ad3d82
|
Assos Assos
|
} |