summaryrefslogtreecommitdiff
path: root/modules/block.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/block.module')
-rw-r--r--modules/block.module224
1 files changed, 138 insertions, 86 deletions
diff --git a/modules/block.module b/modules/block.module
index 576ca1a10..ded693cef 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -201,80 +201,96 @@ function _block_rehash($order_by = array('weight')) {
* Prepare the main block administration form.
*/
function block_admin_display() {
+ global $theme_key;
+ $throttle = module_exist('throttle');
+
+ $blocks = _block_rehash();
+ $block_regions = system_region_list($theme_key);
+
+ $form[action] = arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block');
+ $form[tree] = TRUE;
+ foreach ($blocks as $block) {
+ $form[$block['module']][$block['delta']]['info'] = array(type => 'markup', value => $block['info']);
+ $form[$block['module']][$block['delta']]['status'] = array(type => 'checkbox', default_value => $block['status']);
+ $form[$block['module']][$block['delta']]['theme'] = array(type => 'hidden', value => $theme_key);
+ $form[$block['module']][$block['delta']]['weight'] = array(type => 'weight', default_value => $block['weight']);
+ $form[$block['module']][$block['delta']]['region'] = array(type => 'select', default_value => isset($block['region']) ? $block['region'] : system_default_region(), options => $block_regions);
+
+ if ($throttle) {
+ $form[$block['module']][$block['delta']]['throttle'] = array(type => 'checkbox', default_value => $block['throttle']);
+ }
+ $form[$block['module']][$block['delta']]['configure'] = array(type => 'markup', value => l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']));
+ if ($block['module'] == 'block') {
+ $form[$block['module']][$block['delta']]['delete'] = array(type => 'markup', value => l(t('delete'), 'admin/block/delete/'. $block['delta']));
+ }
+ }
+ $form['submit'] = array(type => 'submit', value => t('Save blocks'));
+
+ return drupal_get_form('block_admin_display', $form);
+}
+
+function theme_block_admin_display($form) {
+
global $theme_key, $custom_theme;
+ $throttle = module_exist('throttle');
// If non-default theme configuration has been selected, set the custom theme.
if (arg(3)) {
$custom_theme = arg(3);
init_theme();
}
-
- $blocks = _block_rehash();
-
$block_regions = system_region_list($theme_key);
-
+
// Highlight regions on page, to provide visual reference.
foreach ($block_regions as $key => $value) {
drupal_set_content($key, '<div class="block-region">' . $value . '</div>');
}
-
- $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
- if (module_exist('throttle')) {
- $header[] = t('Throttle');
- }
- $header[] = array('data' => t('Operations'), 'colspan' => 2);
-
$regions = array();
$disabled = array();
-
- foreach ($blocks as $block) {
- if ($block['module'] == 'block') {
- $delete = l(t('delete'), 'admin/block/delete/'. $block['delta']);
- }
- else {
- $delete = '';
- }
-
- $row = array(array('data' => $block['info'], 'class' => 'block'),
- form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']) . form_hidden($block['module'] .']['. $block['delta'] .'][theme', $theme_key),
- form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']),
- form_select(NULL, $block['module'] .']['. $block['delta'] .'][region', isset($block['region']) ? $block['region'] : system_default_region(),
- $block_regions));
-
- if (module_exist('throttle')) {
- $row[] = form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']);
- }
- $row[] = l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']);
- $row[] = $delete;
- if ($block['status']) {
- foreach ($block_regions as $key => $value) {
- if ($block['region'] == $key) {
- $regions[$key][] = $row;
+ foreach (element_children($form) as $module) {
+ // Don't take form control structures
+ if (is_array($form[$module])) {
+ foreach ($form[$module] as $delta => $element) {
+ // Only take form elements that are blocks
+ if (is_array($form[$module][$delta]['info'])) {
+ $block = $form[$module][$delta];
+ $row = array(array('data' => form_render($block['info']), 'class' => 'block'), form_render($block['status']) . form_render($block['theme']), form_render($block['weight']), form_render($block['region']));
+ if ($throttle) {
+ $row[] = form_render($block['throttle']);
+ }
+ $row[] = form_render($block['configure']);
+ $row[] = $block['delete'] ? form_render($block['delete']) : '';
+ if ($block['status'][default_value]) {
+ $regions[$block['region'][default_value]][] = $row;
+ }
+ else if ($block['region'][default_value] <= 1) {
+ $disabled[] = $row;
+ }
}
}
}
- else if ($block['region'] <= 1) {
- $disabled[] = $row;
- }
}
-
+
$rows = array();
-
if (count($regions)) {
foreach ($regions as $region => $row) {
$region_title = t('%region', array ('%region' => ucfirst($block_regions[$region])));
- $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $row);
}
}
if (count($disabled)) {
- $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6)));
+ $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$rows = array_merge($rows, $disabled);
}
+ $header = array(t('Block'), t('Enabled'), t('Weight'), t('Placement'));
+ if ($throttle) {
+ $header[] = t('Throttle');
+ }
+ $header[] = array('data' => t('Operations'), 'colspan' => 2);
$output = theme('table', $header, $rows, array('id' => 'blocks'));
- $output .= form_submit(t('Save blocks'));
-
- return form($output, 'post', arg(3) ? url('admin/block/list/' . $theme_key) : url('admin/block'));
+ $output .= form_render($form['submit']);
+ return $output;
}
function block_box_get($bid) {
@@ -304,7 +320,15 @@ function block_admin_configure($module = NULL, $delta = 0) {
// Module-specific block configurations.
if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
- $form = form_group(t('Block specific settings'), $settings);
+ $form['block_settings'] = array(type => 'fieldset',
+ title => t('Block specific settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ foreach ($settings as $k => $v) {
+ $form['block_settings'][$k] = $v;
+ }
}
// Get the block subject for the page title.
@@ -312,16 +336,46 @@ function block_admin_configure($module = NULL, $delta = 0) {
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])));
// Standard block configurations.
- $group_1 = form_radios(t('Custom visibility settings'), 'custom', $edit['custom'], array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'));
- $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')));
- $group_2 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 60, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
-
- $form .= form_group(t('User specific visibility settings'), $group_1);
- $form .= form_group(t('Page specific visibility settings'), $group_2);
-
- $form .= form_submit(t('Save block'));
-
- return form($form);
+
+ $form['user_vis_settings'] = array(type => 'fieldset',
+ title => t('User specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+ $form['user_vis_settings']['custom'] = array(
+ type => 'radios',
+ title => t('Custom visibility settings'),
+ default_value => $edit['custom'],
+ options => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.'),
+ default_value => $edit['custom']);
+
+
+ $form['page_vis_settings'] = array(type => 'fieldset',
+ title => t('Page specific visibility settings'),
+ collapsible => true,
+ collapsed => false,
+ weight => 0);
+
+
+ $form['page_vis_settings']['visibility'] = array(
+ type => 'radios',
+ title => t('Show block on specific pages'),
+ default_value => $edit['visibility'],
+ options => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')),
+ default_value => $edit['visibility']);
+
+ $form['page_vis_settings']['pages'] = array(
+ type => 'textarea',
+ title => t('Pages'),
+ default_value => $edit['pages'],
+ cols => 60,
+ rows => 5,
+ description => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))));
+
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
+
+ return drupal_get_form('block_config', $form);
}
}
@@ -341,45 +395,42 @@ function block_box_add() {
// deliberate no break
default:
$form = block_box_form($edit);
- $form .= form_submit(t('Save block'));
- $output .= form($form);
+ $form['submit'] = array(type => 'submit', value => t('Save block'));
}
- return $output;
+ return drupal_get_form('block_box_add', $form);
}
/**
- * Menu callback; confirm and delete custom blocks.
+ * Menu callback; confirm deletion of custom blocks.
*/
function block_box_delete($bid = 0) {
- $op = $_POST['op'];
$box = block_box_get($bid);
- $info = $box['info'] ? $box['info'] : $box['title'];
-
- if ($_POST['edit']['confirm']) {
- db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
- drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $info))));
- cache_clear_all();
- drupal_goto('admin/block');
- }
- else {
- $output = theme('confirm',
- t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))),
- 'admin/block',
- NULL,
- t('Delete'));
- }
+ $form['info'] = array(type => 'hidden', value => $box['info'] ? $box['info'] : $box['title']);
+ $form['bid'] = array(type => 'hidden', value => $bid);
- return $output;
+ return confirm_form('block_box_delete_confirm', $form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $info))), 'admin/block', '', t('Delete'), t('Cancel'));
}
+/**
+ * Deletion of custom blocks.
+ */
+function block_box_delete_confirm_execute($form_id, $edit) {
+ $form = $GLOBALS['form_values'];
+ db_query('DELETE FROM {boxes} WHERE bid = %d', $form['bid']);
+ drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form['info']))));
+ cache_clear_all();
+ drupal_goto('admin/block');
+};
+
+
function block_box_form($edit = array()) {
- $output = form_textfield(t('Block title'), 'title', $edit['title'], 60, 64, t('The title of the block as shown to the user.'));
- $output .= filter_form('format', $edit['format']);
- $output .= form_textarea(t('Block body'), 'body', $edit['body'], 60, 15, t('The content of the block as shown to the user.'));
- $output .= form_textfield(t('Block description'), 'info', $edit['info'], 60, 64, t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), NULL, TRUE);
+ $form['title'] = array(type => 'textfield', title => t('Block title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The title of the block as shown to the user.'));
+ $form['format'] = filter_form($edit['format']);
+ $form['body'] = array(type => 'textarea', title => t('Block body'), default_value => $edit['body'], cols => 60, rows => 15, description => t('The content of the block as shown to the user.'));
+ $form['info'] = array(type => 'textfield', title => t('Block description'), default_value => $edit['info'], size => 60, maxlength => 64, description => t('A brief description of your block. Used on the <a href="%overview">block overview page</a>.', array('%overview' => url('admin/block'))), required => TRUE);
- return $output;
+ return $form;
}
function block_box_save($edit, $delta = NULL) {
@@ -427,16 +478,17 @@ function block_user($type, $edit, &$user, $category = NULL) {
case 'form':
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE status = 1 AND custom != 0 ORDER BY weight, module, delta');
-
+ $form['block'] = array(type => 'fieldset', title => t('Block configuration'), weight => 3, collapsible => TRUE, collapsed => FALSE, tree => TRUE);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
- $form .= form_checkbox($data[$block->delta]['info'], 'block]['. $block->module .']['. $block->delta, 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
+ $return = TRUE;
+ $form['block'][$block->module][$block->delta] = array(type => 'checkbox', title => $data[$block->delta]['info'], default_value => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
}
}
- if (isset($form)) {
- return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2));
+ if ($return) {
+ return $form;
}
}