Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/plugins/views_plugin_display_block.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Contains the block display plugin.
|
|
5 |
* Definition of views_plugin_display_block.
|
|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
... | ... | |
11 | 11 |
* @ingroup views_display_plugins |
12 | 12 |
*/ |
13 | 13 |
class views_plugin_display_block extends views_plugin_display { |
14 |
function option_definition() { |
|
14 |
|
|
15 |
/** |
|
16 |
* {@inheritdoc} |
|
17 |
*/ |
|
18 |
public function option_definition() { |
|
15 | 19 |
$options = parent::option_definition(); |
16 | 20 |
|
17 | 21 |
$options['block_description'] = array('default' => '', 'translatable' => TRUE); |
... | ... | |
25 | 29 |
* but extended block handlers might be able to do interesting |
26 | 30 |
* stuff with it. |
27 | 31 |
*/ |
28 |
function execute_hook_block_list($delta = 0, $edit = array()) { |
|
32 |
public function execute_hook_block_list($delta = 0, $edit = array()) {
|
|
29 | 33 |
$delta = $this->view->name . '-' . $this->display->id; |
30 | 34 |
$desc = $this->get_option('block_description'); |
31 | 35 |
|
... | ... | |
40 | 44 |
return array( |
41 | 45 |
$delta => array( |
42 | 46 |
'info' => $desc, |
43 |
'cache' => $this->get_cache_type() |
|
47 |
'cache' => $this->get_cache_type(),
|
|
44 | 48 |
), |
45 | 49 |
); |
46 | 50 |
} |
... | ... | |
48 | 52 |
/** |
49 | 53 |
* The display block handler returns the structure necessary for a block. |
50 | 54 |
*/ |
51 |
function execute() { |
|
55 |
public function execute() {
|
|
52 | 56 |
// Prior to this being called, the $view should already be set to this |
53 | 57 |
// display, and arguments should be set on the view. |
54 | 58 |
$info['content'] = $this->view->render(); |
... | ... | |
64 | 68 |
* |
65 | 69 |
* This output is returned as an array. |
66 | 70 |
*/ |
67 |
function options_summary(&$categories, &$options) { |
|
68 |
// It is very important to call the parent function here:
|
|
71 |
public function options_summary(&$categories, &$options) {
|
|
72 |
// It is very important to call the parent function here.
|
|
69 | 73 |
parent::options_summary($categories, $options); |
70 | 74 |
|
71 | 75 |
$categories['block'] = array( |
... | ... | |
98 | 102 |
/** |
99 | 103 |
* Provide a list of core's block caching modes. |
100 | 104 |
*/ |
101 |
function block_caching_modes() { |
|
105 |
public function block_caching_modes() {
|
|
102 | 106 |
return array( |
103 | 107 |
DRUPAL_NO_CACHE => t('Do not cache'), |
104 | 108 |
DRUPAL_CACHE_GLOBAL => t('Cache once for everything (global)'), |
... | ... | |
114 | 118 |
* Provide a single method to figure caching type, keeping a sensible default |
115 | 119 |
* for when it's unset. |
116 | 120 |
*/ |
117 |
function get_cache_type() { |
|
121 |
public function get_cache_type() {
|
|
118 | 122 |
$cache_type = $this->get_option('block_caching'); |
119 | 123 |
if (empty($cache_type)) { |
120 | 124 |
$cache_type = DRUPAL_NO_CACHE; |
... | ... | |
125 | 129 |
/** |
126 | 130 |
* Provide the default form for setting options. |
127 | 131 |
*/ |
128 |
function options_form(&$form, &$form_state) { |
|
129 |
// It is very important to call the parent function here:
|
|
132 |
public function options_form(&$form, &$form_state) {
|
|
133 |
// It is very important to call the parent function here.
|
|
130 | 134 |
parent::options_form($form, $form_state); |
131 | 135 |
|
132 | 136 |
switch ($form_state['section']) { |
... | ... | |
138 | 142 |
'#default_value' => $this->get_option('block_description'), |
139 | 143 |
); |
140 | 144 |
break; |
145 |
|
|
141 | 146 |
case 'block_caching': |
142 | 147 |
$form['#title'] .= t('Block caching type'); |
143 | 148 |
|
... | ... | |
148 | 153 |
'#default_value' => $this->get_cache_type(), |
149 | 154 |
); |
150 | 155 |
break; |
156 |
|
|
151 | 157 |
case 'exposed_form_options': |
152 | 158 |
$this->view->init_handlers(); |
153 | 159 |
if (!$this->uses_exposed() && parent::uses_exposed()) { |
... | ... | |
156 | 162 |
'#markup' => '<div class="messages warning">' . t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>', |
157 | 163 |
); |
158 | 164 |
} |
165 |
break; |
|
159 | 166 |
} |
160 | 167 |
} |
161 | 168 |
|
... | ... | |
163 | 170 |
* Perform any necessary changes to the form values prior to storage. |
164 | 171 |
* There is no need for this function to actually store the data. |
165 | 172 |
*/ |
166 |
function options_submit(&$form, &$form_state) { |
|
167 |
// It is very important to call the parent function here:
|
|
173 |
public function options_submit(&$form, &$form_state) {
|
|
174 |
// It is very important to call the parent function here.
|
|
168 | 175 |
parent::options_submit($form, $form_state); |
169 | 176 |
switch ($form_state['section']) { |
170 | 177 |
case 'display_id': |
171 | 178 |
$this->update_block_bid($form_state['view']->name, $this->display->id, $this->display->new_id); |
172 | 179 |
break; |
180 |
|
|
173 | 181 |
case 'block_description': |
174 | 182 |
$this->set_option('block_description', $form_state['values']['block_description']); |
175 | 183 |
break; |
184 |
|
|
176 | 185 |
case 'block_caching': |
177 | 186 |
$this->set_option('block_caching', $form_state['values']['block_caching']); |
178 |
$this->save_block_cache($form_state['view']->name . '-'. $form_state['display_id'], $form_state['values']['block_caching']); |
|
187 |
$this->save_block_cache($form_state['view']->name . '-' . $form_state['display_id'], $form_state['values']['block_caching']);
|
|
179 | 188 |
break; |
180 | 189 |
} |
181 | 190 |
} |
... | ... | |
183 | 192 |
/** |
184 | 193 |
* Block views use exposed widgets only if AJAX is set. |
185 | 194 |
*/ |
186 |
function uses_exposed() { |
|
187 |
if ($this->use_ajax()) { |
|
188 |
return parent::uses_exposed(); |
|
189 |
} |
|
190 |
return FALSE; |
|
195 |
public function uses_exposed() { |
|
196 |
if ($this->use_ajax()) { |
|
197 |
return parent::uses_exposed(); |
|
191 | 198 |
} |
199 |
return FALSE; |
|
200 |
} |
|
192 | 201 |
|
193 | 202 |
/** |
194 |
* Update the block delta when you change the machine readable name of the display.
|
|
203 |
* Update the block delta when the machine name of the display changes.
|
|
195 | 204 |
*/ |
196 |
function update_block_bid($name, $old_delta, $delta) { |
|
205 |
public function update_block_bid($name, $old_delta, $delta) {
|
|
197 | 206 |
$old_hashes = $hashes = variable_get('views_block_hashes', array()); |
198 | 207 |
|
199 | 208 |
$old_delta = $name . '-' . $old_delta; |
... | ... | |
224 | 233 |
|
225 | 234 |
/** |
226 | 235 |
* Save the block cache setting in the blocks table if this block already |
227 |
* exists in the blocks table. Dirty fix until http://drupal.org/node/235673 gets in. |
|
236 |
* exists in the blocks table. Dirty fix until http://drupal.org/node/235673 |
|
237 |
* gets in. |
|
228 | 238 |
*/ |
229 |
function save_block_cache($delta, $cache_setting) { |
|
239 |
public function save_block_cache($delta, $cache_setting) {
|
|
230 | 240 |
if (strlen($delta) >= 32) { |
231 | 241 |
$delta = md5($delta); |
232 | 242 |
} |
233 |
if (db_table_exists('block') && $bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array( |
|
234 |
':delta' => $delta))->fetchField()) { |
|
243 |
if (db_table_exists('block') && $bid = db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array(':delta' => $delta))->fetchField()) { |
|
235 | 244 |
db_update('block') |
236 | 245 |
->fields(array( |
237 |
'cache' => $cache_setting, |
|
246 |
'cache' => $cache_setting,
|
|
238 | 247 |
)) |
239 |
->condition('module','views') |
|
248 |
->condition('module', 'views')
|
|
240 | 249 |
->condition('delta', $delta) |
241 | 250 |
->execute(); |
242 | 251 |
} |
243 | 252 |
} |
253 |
|
|
244 | 254 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules