| 1 |
<?php
|
| 2 |
// $Id: blockregion.module,v 1.4.2.3 2008/02/06 10:33:27 ax Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Enables the configuration of blocks for all themes at once.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function blockregion_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/modules#description':
|
| 15 |
return t('Enable the configuration of blocks for all themes at once.');
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_form_alter().
|
| 21 |
*
|
| 22 |
* Add checkboxes for "apply to all themes", change submit handler.
|
| 23 |
*/
|
| 24 |
function blockregion_form_alter(&$form_id, &$form) {
|
| 25 |
if ($form_id == 'block_admin_display') {
|
| 26 |
$form['all_themes'] = array(
|
| 27 |
'#type' => 'fieldset',
|
| 28 |
'basic' => array(
|
| 29 |
'#type' => 'checkbox',
|
| 30 |
'#title' => t('Apply all settings except "Region" to all themes\' blocks?'),
|
| 31 |
'#default_value' => FALSE,
|
| 32 |
),
|
| 33 |
'regions' => array(
|
| 34 |
'#type' => 'checkbox',
|
| 35 |
'#title' => t('Apply "Region" to all themes that have the same regions as this theme?'),
|
| 36 |
'#default_value' => FALSE,
|
| 37 |
),
|
| 38 |
);
|
| 39 |
/*
|
| 40 |
TODO: find a way to hook into theme_block_admin_display()s strange
|
| 41 |
$output = theme('table',...);
|
| 42 |
$output .= drupal_render($form);
|
| 43 |
to display $form['all_themes'] and the (second) submit button on top of the form.
|
| 44 |
|
| 45 |
// add an extra submit button for the top
|
| 46 |
$form['submit2'] = array('#type' => 'submit', '#value' => t('Save blocks'));
|
| 47 |
// custom function for controlled rendering of above - theme_block_admin_display() doesn't
|
| 48 |
$form['#theme'] = 'blockregion_admin_display';
|
| 49 |
*/
|
| 50 |
$form['#submit'] = array('blockregion_admin_display_submit' => TRUE);
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Custom submit handler.
|
| 56 |
*/
|
| 57 |
function blockregion_admin_display_submit($form_id, $form_values) {
|
| 58 |
foreach ($form_values as $block) {
|
| 59 |
$block['status'] = $block['region'] != BLOCK_REGION_NONE;
|
| 60 |
$block['region'] = $block['status'] ? $block['region'] : '';
|
| 61 |
|
| 62 |
// Apply all settings except "Region" to all themes\' blocks?
|
| 63 |
list($placeholder, $replacement) = !$form_values['all_themes']['basic'] ? array(" AND theme = '%s'", $block['theme']) : array('', '');
|
| 64 |
db_query("UPDATE {blocks} SET status = %d, weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'$placeholder", $block['status'], $block['weight'], isset($block['throttle']) ? $block['throttle'] : 0, $block['module'], $block['delta'], $replacement);
|
| 65 |
|
| 66 |
// Apply "Region" to all themes that have the same regions as this theme?
|
| 67 |
$themes = $form_values['all_themes']['regions'] ? array_keys(list_themes()) : array($block['theme']);
|
| 68 |
foreach ($themes as $theme) {
|
| 69 |
if (system_region_list($theme) == system_region_list($block['theme'])) {
|
| 70 |
db_query("UPDATE {blocks} SET region = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['region'], $block['module'], $block['delta'], $theme);
|
| 71 |
$region_applied[$theme] = TRUE;
|
| 72 |
}
|
| 73 |
}
|
| 74 |
}
|
| 75 |
drupal_set_message(t('Block settings have been updated for !themes.', array('!themes' => $form_values['all_themes']['basic'] ? t('all themes') : t('this theme'))));
|
| 76 |
drupal_set_message(t('Regions have been set for !themes.', array('!themes' => $form_values['all_themes']['regions'] ? t('the themes %themes', array('%themes' => implode(', ', array_keys($region_applied)))) : t('this theme'))));
|
| 77 |
cache_clear_all();
|
| 78 |
}
|