Révision 64156087
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/panels/includes/common.inc | ||
---|---|---|
39 | 39 |
* |
40 | 40 |
* @see panels_edit_layout() |
41 | 41 |
* @see _panels_edit_layout() |
42 |
* |
|
43 | 42 |
*/ |
44 | 43 |
class panels_allowed_layouts { |
45 | 44 |
|
46 | 45 |
/** |
47 |
* Specifies whether newly-added layouts (as in, new .inc files) should be automatically
|
|
46 |
* Specifies whether newly-added layouts (as in, new .inc files) should be automatically |
|
48 | 47 |
* allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more |
49 | 48 |
* permissive but less of an administrative hassle if/when you add new layouts. Note |
50 | 49 |
* that this parameter will be derived from $allowed_layouts if a value is passed in. |
... | ... | |
52 | 51 |
var $allow_new = TRUE; |
53 | 52 |
|
54 | 53 |
/** |
55 |
* Optional member. If provided, the Panels API will generate a drupal variable using
|
|
54 |
* Optional member. If provided, the Panels API will generate a drupal variable using |
|
56 | 55 |
* variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the |
57 | 56 |
* storage of this object entirely within the Panels API. This object will be |
58 | 57 |
* called and rebuilt by panels_edit_layout() if the same $module_name string is passed in |
59 | 58 |
* for the $allowed_types parameter. \n |
60 | 59 |
* This is primarily intended for convenience - client modules doing heavy-duty implementations |
61 | 60 |
* of the Panels API will probably want to create their own storage method. |
61 |
* |
|
62 | 62 |
* @see panels_edit_layout() |
63 | 63 |
*/ |
64 | 64 |
var $module_name = NULL; |
65 | 65 |
|
66 | 66 |
/** |
67 |
* An associative array of all available layouts, keyed by layout name (as defined
|
|
67 |
* An associative array of all available layouts, keyed by layout name (as defined |
|
68 | 68 |
* in the corresponding layout plugin definition), with value = 1 if the layout is |
69 | 69 |
* allowed, and value = 0 if the layout is not allowed. |
70 | 70 |
* Calling array_filter(panels_allowed_layouts::$allowed_layout_settings) will return an associative array |
... | ... | |
82 | 82 |
|
83 | 83 |
/** |
84 | 84 |
* Constructor function; loads the $allowed_layout_settings array with initial values according |
85 |
* to $start_allowed |
|
85 |
* to $start_allowed.
|
|
86 | 86 |
* |
87 | 87 |
* @param bool $start_allowed |
88 |
* $start_allowed determines whether all available layouts will be marked |
|
89 |
* as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed() |
|
90 |
* |
|
88 |
* $start_allowed determines whether all available layouts will be marked |
|
89 |
* as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed() |
|
91 | 90 |
*/ |
92 | 91 |
function __construct($start_allowed = TRUE) { |
93 |
// TODO would be nice if there was a way to just fetch the names easily |
|
92 |
// TODO would be nice if there was a way to just fetch the names easily.
|
|
94 | 93 |
foreach ($this->list_layouts() as $layout_name) { |
95 | 94 |
$this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0; |
96 | 95 |
} |
... | ... | |
121 | 120 |
* drupal_goto('</path/to/desired/redirect>'); |
122 | 121 |
* } |
123 | 122 |
* } |
123 |
* |
|
124 | 124 |
* @endcode \n |
125 | 125 |
* |
126 | 126 |
* If $allowed_layouts->form_state == 'failed-validate' || 'render', then you'll need to return |
... | ... | |
135 | 135 |
* you to control where the user ends up next. |
136 | 136 |
* |
137 | 137 |
* @param string $title |
138 |
* Used to set the title of the allowed layouts form. If no value is given, defaults to |
|
139 |
* 'Panels: Allowed Layouts'. |
|
138 |
* Used to set the title of the allowed layouts form. If no value is given, defaults to
|
|
139 |
* 'Panels: Allowed Layouts'.
|
|
140 | 140 |
* |
141 | 141 |
* @return mixed $result |
142 | 142 |
* - On the first passthrough when the form is being rendered, $result is the form's structured |
... | ... | |
147 | 147 |
function set_allowed($title = 'Panels: Allowed Layouts') { |
148 | 148 |
$this->sync_with_available(); |
149 | 149 |
$form_id = 'panels_common_set_allowed_layouts'; |
150 |
// TODO switch to drupal_build_form(); need to pass by ref |
|
150 |
// TODO switch to drupal_build_form(); need to pass by ref.
|
|
151 | 151 |
$form = drupal_retrieve_form($form_id, $this, $title); |
152 | 152 |
|
153 | 153 |
if ($result = drupal_process_form($form_id, $form)) { |
154 |
// successful submit
|
|
154 |
// Successful submit.
|
|
155 | 155 |
$this->form_state = 'submit'; |
156 | 156 |
return $result; |
157 | 157 |
} |
... | ... | |
192 | 192 |
* If you don't serialize the second parameter of variable_get() and the variable name you provide |
193 | 193 |
* can't be found, an E_STRICT warning will be generated for trying to unserialize an entity |
194 | 194 |
* that has not been serialized. |
195 |
* |
|
196 | 195 |
*/ |
197 | 196 |
function save() { |
198 | 197 |
if (!is_null($this->module_name)) { |
199 |
variable_set($this->module_name . '_allowed_layouts', serialize($this));
|
|
198 |
variable_set($this->module_name . "_allowed_layouts", serialize($this));
|
|
200 | 199 |
} |
201 | 200 |
} |
202 | 201 |
|
... | ... | |
217 | 216 |
} |
218 | 217 |
return $layouts; |
219 | 218 |
} |
219 |
|
|
220 | 220 |
} |
221 | 221 |
|
222 | 222 |
/** |
... | ... | |
272 | 272 |
// each type its own checkboxes set unless it's 'single' in which |
273 | 273 |
// case it can go into our fake other set. |
274 | 274 |
$available_content_types = ctools_content_get_all_types(); |
275 |
$allowed_content_types = db_select('panels_allowed_types', 'pat') |
|
276 |
->fields('pat', array('type', 'allowed')) |
|
277 |
->condition('module', $module_name) |
|
278 |
->execute() |
|
279 |
->fetchAllKeyed(); |
|
275 |
$allowed_content_types = variable_get($module_name . '_allowed_types', array()); |
|
280 | 276 |
|
281 | 277 |
foreach ($available_content_types as $id => $types) { |
282 | 278 |
foreach ($types as $type => $info) { |
... | ... | |
296 | 292 |
'#tree' => TRUE, |
297 | 293 |
); |
298 | 294 |
|
299 |
// cheat a bit
|
|
295 |
// Cheat a bit.
|
|
300 | 296 |
$content_types['other'] = array('title' => t('Other'), 'weight' => 10); |
301 | 297 |
foreach ($content_types as $id => $info) { |
302 | 298 |
if (isset($allowed[$id])) { |
... | ... | |
342 | 338 |
} |
343 | 339 |
|
344 | 340 |
/** |
345 |
* Submit hook for panels_common_settings |
|
341 |
* Submit hook for panels_common_settings.
|
|
346 | 342 |
*/ |
347 | 343 |
function panels_common_settings_validate($form, &$form_state) { |
348 | 344 |
panels_common_allowed_layouts_form_validate($form, $form_state); |
349 | 345 |
} |
350 | 346 |
|
351 | 347 |
/** |
352 |
* Submit hook for panels_common_settings |
|
348 |
* Submit hook for panels_common_settings.
|
|
353 | 349 |
*/ |
354 | 350 |
function panels_common_settings_submit($form, &$form_state) { |
355 | 351 |
panels_common_allowed_layouts_form_submit($form, $form_state); |
... | ... | |
358 | 354 |
if (!$form_state['skip']) { |
359 | 355 |
// Merge the broken apart array neatly back together. |
360 | 356 |
$allowed_content_types = array(); |
361 |
$content_types = $form_state['values']['allowed']; |
|
362 |
foreach ($content_types as $content_type) { |
|
363 |
$allowed_content_types = array_merge($allowed_content_types, $form_state['values']['content_types'][$content_type]['options']); |
|
364 |
foreach ($allowed_content_types as $type => $allowed) { |
|
365 |
$allowed = empty($allowed) ? 0 : 1; |
|
366 |
db_merge('panels_allowed_types') |
|
367 |
->key(array('module' => $module_name, 'type' => $type)) |
|
368 |
->fields(array( |
|
369 |
'module' => $module_name, |
|
370 |
'type' => $type, |
|
371 |
'allowed' => $allowed, |
|
372 |
)) |
|
373 |
->execute(); |
|
357 |
foreach ($form_state['values']['allowed'] as $allowed) { |
|
358 |
$values = $form_state['values']['content_types'][$allowed]['options']; |
|
359 |
// If new content of the type is not added, storing a lisy of disabled |
|
360 |
// content is not needed. |
|
361 |
if (!$form_state['values']['panels_common_default'][$allowed]) { |
|
362 |
$values = array_filter($values); |
|
374 | 363 |
} |
364 |
$allowed_content_types = array_merge($allowed_content_types, $values); |
|
375 | 365 |
} |
366 |
// Values from checkboxes are the same string as they key, but we only need |
|
367 |
// to store the boolean value. |
|
368 |
foreach ($allowed_content_types as &$value) { |
|
369 |
$value = (bool) $value; |
|
370 |
} |
|
371 |
variable_set($module_name . '_allowed_types', $allowed_content_types); |
|
376 | 372 |
} |
377 | 373 |
drupal_set_message(t('Your changes have been saved.')); |
378 | 374 |
} |
... | ... | |
381 | 377 |
* Based upon the settings, get the allowed types for this node. |
382 | 378 |
*/ |
383 | 379 |
function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) { |
384 |
// Get a list of all types that are available |
|
380 |
// Get a list of all types that are available.
|
|
385 | 381 |
$default_types = variable_get($module . '_default', $default_defaults); |
386 |
$allowed_types = db_select('panels_allowed_types', 'pat') |
|
387 |
->fields('pat', array('type', 'allowed')) |
|
388 |
->condition('module', $module) |
|
389 |
->execute() |
|
390 |
->fetchAllKeyed(); |
|
391 |
$allowed_types = !empty($allowed_types) ? $allowed_types : $default_allowed_types; |
|
382 |
$allowed_types = variable_get($module . '_allowed_types', $default_allowed_types); |
|
392 | 383 |
|
393 | 384 |
// By default, if they haven't gone and done the initial setup here, |
394 | 385 |
// let all 'other' types (which will be all types) be available. |
... | ... | |
420 | 411 |
* @ingroup forms |
421 | 412 |
* |
422 | 413 |
* @param array $allowed_layouts |
423 |
* The set of allowed layouts that should be used as the default values |
|
424 |
* for this form. If none is provided, then by default no layouts will be restricted. |
|
414 |
* The set of allowed layouts that should be used as the default values
|
|
415 |
* for this form. If none is provided, then by default no layouts will be restricted.
|
|
425 | 416 |
*/ |
426 | 417 |
function panels_common_allowed_layouts_form(&$form, &$form_state, $module_name) { |
427 | 418 |
// Fetch our allowed layouts from variables. |
... | ... | |
434 | 425 |
|
435 | 426 |
$form_state['allowed_layouts'] = &$allowed_layouts; |
436 | 427 |
|
428 |
ctools_add_js('panels-base', 'panels'); |
|
437 | 429 |
ctools_add_js('layout', 'panels'); |
438 | 430 |
|
439 | 431 |
$form['layout_selection'] = array( |
... | ... | |
473 | 465 |
* Get the allowed layout object for the given module. |
474 | 466 |
*/ |
475 | 467 |
function panels_common_get_allowed_layout_object($module_name) { |
476 |
$allowed_layouts = unserialize(variable_get($module_name . '_allowed_layouts', serialize('')));
|
|
468 |
$allowed_layouts = unserialize(variable_get($module_name . "_allowed_layouts", serialize('')));
|
|
477 | 469 |
|
478 |
// if no parameter was provided, or the variable_get failed
|
|
470 |
// If no parameter was provided, or the variable_get failed.
|
|
479 | 471 |
if (!$allowed_layouts) { |
480 |
// still no dice. simply creates a dummy version where all layouts
|
|
472 |
// Still no dice. simply creates a dummy version where all layouts
|
|
481 | 473 |
// are allowed. |
482 | 474 |
$allowed_layouts = new panels_allowed_layouts(); |
483 | 475 |
$allowed_layouts->allow_new = TRUE; |
484 | 476 |
$allowed_layouts->module_name = $module_name; |
485 | 477 |
} |
486 | 478 |
|
487 |
// sanitize allowed layout listing; this is redundant if the
|
|
488 |
// $allowed_layouts param was null, but the data is cached anyway |
|
479 |
// Sanitize allowed layout listing; this is redundant if the
|
|
480 |
// $allowed_layouts param was null, but the data is cached anyway.
|
|
489 | 481 |
$allowed_layouts->sync_with_available(); |
490 | 482 |
|
491 | 483 |
return $allowed_layouts; |
... | ... | |
500 | 492 |
if (empty($module_name)) { |
501 | 493 |
return $available_layouts; |
502 | 494 |
} |
503 |
else if (is_object($module_name)) {
|
|
495 |
elseif (is_object($module_name)) { |
|
504 | 496 |
$allowed_layouts = $module_name; |
505 | 497 |
} |
506 | 498 |
else { |
... | ... | |
515 | 507 |
} |
516 | 508 |
} |
517 | 509 |
|
518 |
// Sort |
|
510 |
// Sort.
|
|
519 | 511 |
$layouts = array(); |
520 | 512 |
|
521 | 513 |
asort($order); |
... | ... | |
603 | 595 |
// We're doing these dependencies completely manualy, which is unusual, but |
604 | 596 |
// the process code only supports doing them in a form. |
605 | 597 |
// @todo modify dependent.inc to make this easier. |
606 |
|
|
607 | 598 |
$dependencies = array(); |
608 | 599 |
foreach ($options as $category => $links) { |
609 | 600 |
$dependencies['panels-layout-category-' . $category] = array( |
Formats disponibles : Unified diff
Weekly update of contrib modules