Commit 81be80a5 authored by q0rban's avatar q0rban

Initial commit.

parents
$Id$
********************************************************************************
Region Manager provides a simple interface to manage blocks, and combined with
the nodeblock module, add new blocks to regions. You can specify which regions
for each theme can be managed. After clicking the link to configure a region,
an interface is provided for managing which blocks are visible ON THE PAGE from
which the link was clicked.
The list of which blocks are available can be configured per theme, per region,
per module, or even per block. For example, you can specify that menu module
blocks are only available in the header, or that the navigation menu block is
not available for any region.
Recommended additional modules are nodeblock, and region_visibility.
\ No newline at end of file
<?php
// $Id$
/**
* @file block-admin-display-form.tpl.php
* Default theme implementation to configure blocks.
*
* Available variables:
* - $block_regions: An array of regions. Keyed by name with the title as value.
* - $block_listing: An array of blocks keyed by region and then delta.
* - $form_submit: Form submit button.
*
* Each $block_listing[$region] contains an array of blocks for that region.
*
* Each $data in $block_listing[$region] contains:
* - $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_form()
* @see theme_block_admin_display()
*/
?>
<?php
// Add table javascript.
drupal_add_js('misc/tableheader.js');
drupal_add_js(drupal_get_path('module', 'region_manager') .'/region_manager.js');
drupal_add_js(array('block_name' => _region_manager_block_name()), 'setting');
foreach ($block_regions as $region => $title) {
drupal_add_tabledrag('blocks', 'match', 'sibling', 'block-region-select', 'block-region-'. $region, NULL, FALSE);
drupal_add_tabledrag('blocks', 'order', 'sibling', 'block-weight', 'block-weight-'. $region);
}
?>
<table id="blocks" class="sticky-enabled">
<tbody>
<?php $row = 0; ?>
<?php foreach ($block_regions as $region => $title): ?>
<tr class="region region-<?php print $region?>">
<td colspan="4" class="region"><?php print $title; ?></td>
</tr>
<tr class="region-message region-<?php print $region?>-message <?php print empty($block_listing[$region]) ? 'region-empty' : 'region-populated'; ?>">
<td colspan="4"><em><?php print t('No @blocks', array('@block' => _region_manager_block_name())); ?></em></td>
</tr>
<?php foreach ($block_listing[$region] as $delta => $data): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even'; ?><?php print $data->row_class ? ' '. $data->row_class : ''; ?>">
<td class="block"><?php print $data->block_title; ?></td>
<td><?php print $data->region_select; ?></td>
<td><?php print $data->weight_select; ?></td>
<td class="title-link"><?php print $data->title_link; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php print $form_submit; ?>
<?php
// $Id$
/**
* @file
* Holds all administration forms for region_manager.
*/
/**
* Configuration settings form.
*/
function region_manager_settings_form() {
$form = array();
$form['region_manager_block_name'] = array(
'#type' => 'textfield',
'#title' => t('What should a "Block" be called?'),
'#description' => t('Please note: this only changes the name "Block" within the region manager UI, not throughout your Drupal site.'),
'#default_value' => variable_get('region_manager_block_name', 'Block'),
);
$form = system_settings_form($form);
// Uncomment and update the callback to override the default system settings submit handler.
// $form['#submit'] = array('_settings_form_submit');
return $form;
}
/**
* Region settings form.
*/
function region_manager_regions_form() {
$form = array();
drupal_clear_css_cache();
$themes = system_theme_data();
$settings = variable_get('region_manager_regions', array());
module_load_include('inc', 'system', 'system.admin');
uasort($themes, 'system_sort_modules_by_info_name');
$form['region_manager_regions']['#tree'] = TRUE;
foreach($themes as $theme) {
if ($theme->status) {
$form['region_manager_regions'][$theme->name] = array(
'#type' => 'fieldset',
'#title' => $theme->info['name'],
'#tree' => TRUE,
);
foreach (system_region_list($theme->name) as $region => $title) {
$form['region_manager_regions'][$theme->name][$region] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => $settings[$theme->name][$region],
);
}
}
}
$form = system_settings_form($form);
// Uncomment and update the callback to override the default system settings submit handler.
// $form['submit'] = array('region_manager_regions_form_submit');
return $form;
}
/**
* Block settings form.
*/
function region_manager_blocks_form(&$form_state, $theme_key) {
$form = array();
$roles = user_roles();
$regions = region_manager_region_list($theme_key);
$records = region_manager_regions_load($theme_key);
if (empty($regions)) {
drupal_set_message(t('You must first enable some regions for this theme <a href="!href">here</a>.', array('!href' => 'admin/settings/region_manager')), 'error');
return array();
}
$form['#theme_key'] = $theme_key;
$form['blocked_blocks']['#tree'] = TRUE;
$form['regions']['#tree'] = TRUE;
foreach(array_keys($regions) as $region) {
// rid is the theme key and region delimited by a colon.
$rid = $theme_key .':'. $region;
// Now build each module form.
foreach(_region_manager_block_rehash($theme_key) as $module => $blocks) {
// Add the label for this module to the block_names column.
$form['regions']['block_names']['modules'][$module] = array(
'#type' => 'markup',
'#value' => t('all @module blocks', array('@module' => $module)),
);
// The select box for the module.
$form['regions'][$region]['modules'][$module] = array(
'#type' => 'select',
'#default_value' => isset($records[$rid]['modules'][$module]) ? $records[$rid]['modules'][$module] : REGION_MANAGER_ALL_ENABLED,
'#options' => array(
REGION_MANAGER_ALL_ENABLED => t('All enabled'),
REGION_MANAGER_ALL_DISABLED => t('All disabled'),
REGION_MANAGER_CUSTOM => t('Custom per block'),
),
);
// Now, build the checkboxes for each blocks.
foreach($blocks as $delta => $block) {
// Add the label for this block to the block_names column.
$key = $module .':'. $delta;
$form['regions']['block_names']['blocked_blocks'][$module][$delta] = array(
'#type' => 'markup',
'#value' => $block['info'],
);
// The checkbox for the block.
$form['regions'][$region]['blocked_blocks'][$module][$delta] = array(
'#type' => 'checkbox',
'#default_value' => !in_array($key, (array) $records[$rid]['blocked_blocks']),
);
// Set tree to TRUE.
$form['regions'][$region]['blocked_blocks'][$module]['#tree'] = $form['regions'][$region]['blocked_blocks'][$module][$delta]['#tree'] = TRUE;
}
}
// Set tree to true for these arrays.
$form['regions'][$region]['#tree'] = $form['regions'][$region]['modules']['#tree'] = TRUE;
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
/**
* Submit handler for region_manager_blocks_form
*/
function region_manager_blocks_form_submit($form, &$form_state) {
$regions = $form_state['values']['regions'];
$theme_key = $form['#theme_key'];
foreach($regions as $region => $record) {
// Set the rid for this record.
$record['rid'] = $theme_key .':'. $region;
// Now go through the modules.
foreach($record['modules'] as $module => $module_val) {
foreach($record['blocked_blocks'][$module] as $delta => $block_val) {
// We were using the [module][delta] structure to ease in theming, but we
// need it to be set with just a module:delta key, so let's do that now.
$key = $module .':'. $delta;
$record['blocked_blocks'][$key] = $block_val;
// Now we switch through the $module_val to determine what needs to be done.
switch($module_val) {
case REGION_MANAGER_ALL_ENABLED:
// All are enabled, so unset all.
unset($record['blocked_blocks'][$key]);
break;
case REGION_MANAGER_CUSTOM:
// We don't want to save the checked blocks, only unchecked blocks.
if ($block_val) {
unset($record['blocked_blocks'][$key]);
}
break;
case REGION_MANAGER_ALL_DISABLED:
// Nothing to do here, since we want all of them.
break;
}
}
// Unset this module's array since we resaved using the module:delta format.
unset($record['blocked_blocks'][$module]);
}
// Flip the array, as all we need are the keys at this point.
$record['blocked_blocks'] = implode(', ', array_keys($record['blocked_blocks']));
region_manager_region_save($record);
}
drupal_set_message(t('The changes have been saved.'));
}
/**
* Theme the region_manager_blocks_form.
*
* @ingroup themeable
*/
function theme_region_manager_blocks_form($form) {
if (empty($form['blocked_blocks'])) {
return;
}
drupal_add_js(drupal_get_path('module', 'region_manager') .'/region_manager.admin.js');
$output = '';
$regions = region_manager_region_list($form['#theme_key']);
$header = array();
$header[] = (t('Block'));
foreach($regions as $region => $title) {
$header[] = $title;
}
foreach(element_children($form['regions']) as $region) {
foreach(element_children($form['regions'][$region]['modules']) as $module) {
$data = drupal_render($form['regions'][$region]['modules'][$module]);
$classes = 'region_manager_module-'. $module .' region_manager_region-'. $region;
$rows[$module]['data'][$region] = array('data' => $data, 'class' => $classes);
if (!isset($rows[$module]['class'])) {
$rows[$module]['class'] = $module .' module';
}
foreach(element_children($form['regions'][$region]['blocked_blocks'][$module]) as $delta) {
$key = $module .':'. $delta;
$data = drupal_render($form['regions'][$region]['blocked_blocks'][$module][$delta]);
$classes = 'region_manager_module-'. $module .' region_manager_region-'. $region;
$rows[$key]['data'][$region] = array('data' => $data, 'class' => $classes);
if (!isset($rows[$key]['class'])) {
$rows[$key]['class'] = $module .'-child block';
}
}
}
}
$output .= theme('table', $header, $rows, array('id' => 'regionmanager-regions'));
$output .= drupal_render($form);
return $output;
}
\ No newline at end of file
// $Id$
$(function() {
// Block administration page.
var selects = $('#region-manager-blocks-form tr.module select');
selects.change(function() {
var module = $(this).parents('tr').getClassNames().slice(0, 1);
showHideRows(module);
var classes = $(this).parents('td').getClassNames();
// build our selector from the classes
var selector = 'td.' + classes.join('.');
blockCheckboxes(this.value, selector);
});
selects.change();
});
showHideRows = function(module) {
var show = 0;
$('#region-manager-blocks-form tr.module.' + module + ' select').each(function(i) {
if (this.value == 2) {
show = 1;
}
});
if (show) {
$('#region-manager-blocks-form tr[class^=' + module + ']').not('tr.' + module).show();
}
else {
$('#region-manager-blocks-form tr[class^=' + module + ']').not('tr.' + module).hide();
}
}
blockCheckboxes = function(value, selector) {
switch(value) {
case '0':
$(selector + ' input').not('[id*=all-blocks]').attr('checked', 1);
$(selector + ' input').not('[id*=all-blocks]').attr('disabled', 1);
break;
case '1':
$(selector + ' input').not('[id*=all-blocks]').attr('checked', 0);
$(selector + ' input').not('[id*=all-blocks]').attr('disabled', 1);
break;
case '2':
$(selector + ' input').not('[id*=all-blocks]').attr('disabled', 0);
break;
}
}
$.fn.getClassNames = function() {
if (name = this.attr("class")) {
return name.split(" ");
}
else {
return [];
}
}
\ No newline at end of file
/* $Id$ */
#region-manager-blocks-form tr.module td {
border-top: 1.5em solid #fff;
border-bottom: 1px solid #b4d7f0;
background-color: #d4e7f3;
color: #455067;
font-weight: bold;
}
html.js #region-manager-manage-form select.block-region-select,
html.js #region-manager-manage-form div.region-manager-block-title-wrapper,
#region-manager-manage-form div.region-manager-block-title-wrapper div.form-radios,
#region-manager-manage-form td.title-link a {
display: none;
}
html.js #region-manager-manage-form td.title-link a {
display: inline;
}
html.js #region-manager-manage-form div.region-manager-block-title-wrapper div.form-radios {
display: block;
}
#region-manager-manage-form td.title-link {
text-align: right;
vertical-align: top;
}
#region-manager-manage-form .draggable a.tabledrag-handle {
height: 100%;
}
\ No newline at end of file
; $Id$
name = Region Manager
description = Implements 'add new' block controls to select regions.
; dependencies[] =
core = 6.x
\ No newline at end of file
<?php
// $Id$
/**
* @file
* Install file for database schema
*/
/**
* Implementation of hook_install().
*/
function region_manager_install() {
drupal_install_schema('region_manager');
}
/**
* Implementation of hook_schema().
*/
function region_manager_schema() {
$schema = array();
$schema['region_manager_regions'] = array(
'description' => 'Describes {blocks} access per region.',
'fields' => array(
'rid' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '0',
'description' => 'A region ID, defined by the theme key and region.',
),
'blocked_blocks' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'description' => "List of blocks that are disallowed for this region.",
),
'modules' => array(
'type' => 'text',
'size' => 'big',
'description' => 'A serialized array of module settings for this region.',
'serialize' => TRUE,
'serialized default' => 'a:0:{}',
),
),
'primary key' => array('rid'),
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function region_manager_uninstall() {
drupal_uninstall_schema('region_manager');
variable_del('region_manager_block_name');
variable_del('region_manager_regions');
}
// $Id$
$(function() {
// Move the textfields next to the label for the Use custom title radio.
/*
$('td.block div.region-manager-block-title-wrapper input.form-text').each(function () {
var title = $(this).parent();
$('input.form-radio', title.prev().children()).each(function () {
if ($(this).val() == 1) {
$(this).parent().parent().append(title);
}
});
});
*/
$('input.region-manager-manage-form-title-status').change(function() {
if (this.checked) {
var id = $(this).attr('id');
var textfield = $('input.form-text', $(this).parents('td.block'));
switch (this.value) {
case '0':
textfield.val('').hide('fast');
break;
case '1':
textfield.val('<none>').hide();
break;
case '2':
if (textfield.val() == '<none>') {
textfield.val('');
}
textfield.show('fast');
break;
}
}
});
// Simulate a change so we can disable the title field if need be.
$('input.region-manager-manage-form-title-status').change();
$('td.title-link a').click(function() {
var class = $(this).attr('class');
var wrapper = $('div.' + class);
if (wrapper.is(':hidden')) {
wrapper.show('fast');
}
else {
wrapper.hide('fast');
}
return false;
});
});
/**
* Move a block in the blocks table from one region to another via select list.
*
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
Drupal.behaviors.blockDrag = function(context) {
var table = $('table#blocks');
var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object.
// Add a handler for when a row is swapped, update empty regions.
tableDrag.row.prototype.onSwap = function(swappedRow) {
checkEmptyRegions(table, this);
};
// A custom message for the blocks page specifically.
Drupal.theme.tableDragChangedWarning = function () {
return '<div class="warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these @blocks will not be saved until the <em>@save</em> button is clicked.", { '@block' : Drupal.settings.block_name, '@save' : "Save " + Drupal.settings.block_name }) + '</div>';
};
// Add a handler so when a row is dropped, update fields dropped into new regions.
tableDrag.onDrop = function() {
dragObject = this;
if ($(dragObject.rowObject.element).prev('tr').is('.region-message')) {
var regionRow = $(dragObject.rowObject.element).prev('tr').get(0);
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
var regionField = $('select.block-region-select', dragObject.rowObject.element);
var weightField = $('select.block-weight', dragObject.rowObject.element);
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
if (!regionField.is('.block-region-'+ regionName)) {
regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName);
weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName);
regionField.val(regionName);
}
}
};
// Add the behavior to each region select list.
$('select.block-region-select:not(.blockregionselect-processed)', context).each(function() {
$(this).change(function(event) {
// Make our new row and select field.
var row = $(this).parents('tr:first');
var select = $(this);
tableDrag.rowObject = new tableDrag.row(row);
// Find the correct region and insert the row as the first in the region.
$('tr.region-message', table).each(function() {
if ($(this).is('.region-' + select[0].value + '-message')) {
// Add the new row and remove the old one.
$(this).after(row);
// Manually update weights and restripe.
tableDrag.updateFields(row.get(0));
tableDrag.rowObject.changed = true;
if (tableDrag.oldRowElement) {
$(tableDrag.oldRowElement).removeClass('drag-previous');
}
tableDrag.oldRowElement = row.get(0);
tableDrag.restripeTable();
tableDrag.rowObject.markChanged();
tableDrag.oldRowElement = row;
$(row).addClass('drag-previous');
}
});
// Modify empty regions with added or removed fields.
checkEmptyRegions(table, row);
// Remove focus from selectbox.
select.get(0).blur();
});
$(this).addClass('blockregionselect-processed');
});
var checkEmptyRegions = function(table, rowObject) {
$('tr.region-message', table).each(function() {
// If the dragged row is in this region, but above the message row, swap it down one space.
if ($(this).prev('tr').get(0) == rowObject.element) {
// Prevent a recursion problem when using the keyboard to move rows up.
if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
rowObject.swap('after', this);
}
}
// This region has become empty
if ($(this).next('tr').not('.locked').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
$(this).removeClass('region-populated').addClass('region-empty');
}
// This region has become populated.
else if ($(this).is('.region-empty')) {
$(this).removeClass('region-empty').addClass('region-populated');
}
});
};
};
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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