Commit de06bb7a authored by Dries's avatar Dries
Browse files

- Patch #159936 by dvessel: tpl-ified the block.module.

parent 71f1192f
<?php
// $Id
/**
* @file block-admin-display.tpl.php
* Default theme implementation to configure blocks.
*
* Available variables:
* - $block_listing: An array of block controls within regions.
* - $form_submit: Form submit button.
* - $throttle: TRUE or FALSE depending on throttle module being enabled.
*
* Each $data in $block_listing contains:
* - $data->is_region_first: TRUE or FALSE depending on the listed blocks
* positioning. Used here to insert a region header.
* - $data->region_title: Region title for the listed block.
* - $data->block_title: Block title.
* - $data->region_select: Drop-down menu for assigning a region.
* - $data->weight_select: Drop-down menu for setting weights.
* - $data->throttle_check: Checkbox to enable throttling.
* - $data->configure_link: Block configuration link.
* - $data->delete_link: For deleting user added blocks.
*
* @see template_preprocess_block_admin_display()
* @see theme_block_admin_display()
*/
?>
<?php drupal_add_js('misc/tableheader.js'); ?>
<table id="blocks">
<thead>
<tr>
<th><?php print t('Block'); ?></th>
<th><?php print t('Region'); ?></th>
<th><?php print t('Weight'); ?></th>
<?php if ($throttle): ?>
<th><?php print t('Throttle'); ?></th>
<?php endif; ?>
<th colspan="2"><?php print t('Operations'); ?></th>
</tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($block_listing as $data): ?>
<?php if ($data->is_region_first): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even'; ?>">
<td colspan="<?php print $throttle ? '7' : '6'; ?>" class="region"><?php print $data->region_title; ?></td>
</tr>
<?php $row++; ?>
<?php endif; ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even'; ?>">
<td class="block"><?php print $data->block_title; ?></td>
<td><?php print $data->region_select; ?></td>
<td><?php print $data->weight_select; ?></td>
<?php if ($throttle): ?>
<td><?php print $data->throttle_check; ?></td>
<?php endif; ?>
<td><?php print $data->configure_link; ?></td>
<td><?php print $data->delete_link; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php print $form_submit; ?>
......@@ -300,3 +300,62 @@ function block_box_delete_submit($form, &$form_state) {
return;
}
/**
* Process variables for block-admin-display.tpl.php.
*
* The $variables array contains the following arguments:
* - $form
*
* @see block-admin-display.tpl.php
* @see theme_block_admin_display()
*/
function template_preprocess_block_admin_display(&$variables) {
global $theme_key;
$variables['throttle'] = module_exists('throttle');
$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>');
}
// Setup to track previous region in loop.
$last_region = '';
foreach (element_children($variables['form']) as $i) {
$block = &$variables['form'][$i];
// Only take form elements that are blocks.
if (isset($block['info'])) {
// Fetch region for current block.
$region = $block['region']['#default_value'];
// Track first block listing to insert region header inside block_admin_display.tpl.php.
$is_region_first = FALSE;
if ($last_region != $region) {
$is_region_first = TRUE;
// Set region title. Block regions already translated.
if ($region != BLOCK_REGION_NONE) {
$region_title = drupal_ucfirst($block_regions[$region]);
}
else {
$region_title = t('Disabled');
}
}
$variables['block_listing'][$i]->is_region_first = $is_region_first;
$variables['block_listing'][$i]->region_title = $region_title;
$variables['block_listing'][$i]->block_title = drupal_render($block['info']);
$variables['block_listing'][$i]->region_select = drupal_render($block['region']) . drupal_render($block['theme']);
$variables['block_listing'][$i]->weight_select = drupal_render($block['weight']);
$variables['block_listing'][$i]->throttle_check = $variables['throttle'] ? drupal_render($block['throttle']) : '';
$variables['block_listing'][$i]->configure_link = drupal_render($block['configure']);
$variables['block_listing'][$i]->delete_link = !empty($block['delete']) ? drupal_render($block['delete']) : '';
$last_region = $region;
}
}
$variables['form_submit'] = drupal_render($variables['form']);
}
drupal_rebuild_theme_registry();
......@@ -54,6 +54,7 @@ function block_help($path, $arg) {
function block_theme() {
return array(
'block_admin_display' => array(
'file' => 'block-admin-display',
'arguments' => array('form' => NULL),
),
);
......@@ -218,76 +219,6 @@ function _block_rehash() {
return $blocks;
}
/**
* Theme main block administration form submission.
*
* Note: the blocks are already sorted in the right order,
* grouped by status, region and weight.
*/
function theme_block_admin_display($form) {
global $theme_key;
$throttle = module_exists('throttle');
$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>');
}
// Build rows
$rows = array();
$last_region = '';
$last_status = 1;
foreach (element_children($form) as $i) {
$block = &$form[$i];
// Only take form elements that are blocks.
if (isset($block['info'])) {
// Fetch values
$region = $block['region']['#default_value'];
$status = $region != BLOCK_REGION_NONE;
// Output region header
if ($status && $region != $last_region) {
$region_title = t('@region', array('@region' => drupal_ucfirst($block_regions[$region])));
$rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$last_region = $region;
}
// Output disabled header
elseif ($status != $last_status) {
$rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
$last_status = $status;
}
// Generate block row
$row = array(
array('data' => drupal_render($block['info']), 'class' => 'block'),
drupal_render($block['region']) . drupal_render($block['theme']),
drupal_render($block['weight']),
);
if ($throttle) {
$row[] = drupal_render($block['throttle']);
}
$row[] = drupal_render($block['configure']);
$row[] = !empty($block['delete']) ? drupal_render($block['delete']) : '';
$rows[] = $row;
}
}
// Finish table
$header = array(t('Block'), t('Region'), t('Weight'));
if ($throttle) {
$header[] = t('Throttle');
}
$header[] = array('data' => t('Operations'), 'colspan' => 2);
$output = theme('table', $header, $rows, array('id' => 'blocks'));
$output .= drupal_render($form);
return $output;
}
function block_box_get($bid) {
return db_fetch_array(db_query("SELECT bx.*, bl.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE bl.module = 'block' AND bx.bid = %d", $bid));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment