' : $path;
foreach ($form_state['values'] as $key => $block) {
// Clean up the title.
$block['title'] = trim($block['title']);
// Now let's go through our different states.
switch($block['state']) {
case RM_BLOCK_ACTIVE_PATH:
$block['region'] = $region;
$block['status'] = 1;
// If the block was originally disabled, we need to set it up for our usage.
if ($block['disabled']) {
$block['visibility'] = 1;
$block['pages'] = $path;
}
// If this is a content block and 'expose' was checked, change visibility to 1.
if ($block['expose']) {
$block['visibility'] = 1;
}
// Otherwise, all we need to do is add our path to pages.
elseif (($block['visibility'] == 1) && !preg_match('/^'. preg_quote($path, '/') .'$/im', $block['pages'])) {
$block['pages'] .= empty($block['pages']) ? $path : "\n". $path;
}
break;
case RM_BLOCK_ACTIVE:
$block['region'] = $region;
$block['status'] = 1;
// Remove path from the pages.
$block['pages'] = trim(preg_replace('/^'. preg_quote($path, '/') .'$/im', '', $block['pages']));
// Now check to see if pages is empty, if so, completely disable.
if ($block['visibility'] == 1 && empty($block['pages'])) {
unset($block['disabled']);
$block['status'] = 0;
$block['region'] = '';
}
break;
case RM_BLOCK_DISABLED:
$block['region'] = '';
if ($block['visibility'] == 1) {
$block['pages'] = '';
}
break;
}
db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', visibility = %d, pages = '%s', title = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['title'], $block['module'], $block['delta'], $block['theme']);
}
drupal_set_message(t('The @block settings have been updated.', array('@block' => _region_manager_block_name())));
cache_clear_all();
}
/**
* Process variables for region-manager-manage-form.tpl.php.
*
* The $vars array contains the following arguments:
* - $form
*
* @see region-manager-manage-form.tpl.php
* @see theme_region_manager_manage_form()
*/
function template_preprocess_region_manager_manage_form(&$vars) {
$theme_key = $vars['form']['#region_manager']['theme_key'];
$block_states = $vars['block_states'] = $vars['form']['#block_states'];
$vars['state_prefix'] = $vars['state_suffix'] = array();
foreach ($block_states as $state => $value) {
_region_manager_manage_form_state_wrappers($vars, $state);
$vars['block_listing'][$state] = array();
}
// Initialize disabled blocks array.
$vars['block_listing'][BLOCK_REGION_NONE] = array();
// Set up to track previous region in loop.
$last_state = '';
foreach (element_children($vars['form']) as $i) {
$block = &$vars['form'][$i];
// Only take form elements that are blocks.
if (isset($block['info'])) {
// Fetch state for current block.
$state = $block['state']['#default_value'];
// Set special classes needed for table drag and drop.
$vars['form'][$i]['state']['#attributes']['class'] = 'block-state-select block-state-'. $state;
$vars['form'][$i]['weight']['#attributes']['class'] = 'block-weight block-weight-'. $state;
$vars['block_listing'][$state][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
$vars['block_listing'][$state][$i]->block_modified = isset($block['#attributes']['class']) && strpos($block['#attributes']['class'], 'block-modified') !== FALSE ? TRUE : FALSE;
$vars['block_listing'][$state][$i]->block_config = ''. drupal_render($block['info']) .'';
$vars['block_listing'][$state][$i]->block_config .= '';
$vars['block_listing'][$state][$i]->block_config .= drupal_render($block['title_status']) . drupal_render($block['title']);
$vars['block_listing'][$state][$i]->block_config .= ($block['expose']) ? drupal_render($block['expose']) : '';
$vars['block_listing'][$state][$i]->block_config .= '
';
$vars['block_listing'][$state][$i]->operations = drupal_render($block['operations']);
$vars['block_listing'][$state][$i]->state_select = drupal_render($block['state']) . drupal_render($block['theme']);
$vars['block_listing'][$state][$i]->weight_select = drupal_render($block['weight']);
$last_state = $state;
}
}
$vars['form_submit'] = drupal_render($vars['form']);
}
/**
* Helper function to assemble the prefixes and suffixes for the state tables.
*/
function _region_manager_manage_form_state_wrappers(&$vars, $state) {
$theme_key = $vars['form']['#region_manager']['theme_key'];
$region = $vars['form']['#region_manager']['region'];
$vars['state_prefix'][$state] = $vars['state_suffix'][$state] = '';
switch($state) {
case RM_BLOCK_ACTIVE_PATH:
$vars['state_prefix'][$state] = '';
// Output the create links, if there are any.
if ($links = region_manager_create_links($theme_key, $region)) {
$vars['state_prefix'][$state] .= theme('region_manager_create_menu', $links);
}
break;
case RM_BLOCK_ACTIVE_CONTENT:
$vars['state_prefix'][$state] = '
';
break;
case RM_BLOCK_ACTIVE:
$vars['state_prefix'][$state] = '
';
break;
case RM_BLOCK_DISABLED:
$vars['state_suffix'][$state] = '
';
}
return $output;
}
/**
* Helper function to assemble a list of operations for a block.
*/
function _region_manager_block_operations($block, $key) {
$links = array();
// Set up all the operations.
$args = array('@block' => _region_manager_block_name('upper'));
$ops = array(
'disable' => t('Disable @block completely', $args),
'remove' => t('Remove @block from this page', $args),
'configure' => t('Configure @block', $args),
'add' => t('Add @block to this page', $args),
);
// Get the path and destination.
$path = 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'];
$dest = drupal_get_destination();
foreach($ops as $op => $title) {
$options = array(
'attributes' => array(
'title' => $title,
'class' => $op,
),
'query' => $dest,
);
$links[] = array('data' => l($title, $path, $options), 'class' => 'rm-block-'. $op .'-operation');
}
return theme('item_list', $links, NULL, 'ul', array('class' => 'rm-block-'. $key));
}
/**
* Helper function to determine the state of a block.
*
* @return
* A string signifying the block state.
*/
function _region_manager_block_state($block, $path) {
// Block is disabled and available for use.
if ($block['status'] == 0) {
return RM_BLOCK_DISABLED;
}
// Block is active on this path.
if (_region_manager_block_check_visibility($block, $path)) {
return RM_BLOCK_ACTIVE_PATH;
}
// Block is a content block and only visible on the page from which it was created.
if ($block['visibility'] == -1) {
return RM_BLOCK_ACTIVE_CONTENT;
}
// Block is active elsewhere.
return RM_BLOCK_ACTIVE;
}
/**
* Theme function to output a list of nodeblock content types to add.
*
* @param $links
* An array containing the available content types to add.
* @return
* The HTML list of links.
*/
function theme_region_manager_create_menu($links) {
$output = '';
return $output;
}
/**
* Helper function to determine the status of a title.
*
* Title states:
* 0 = Using the default block title.
* 1 = The title is disabled.
* 2 = A custom title is being used.
*
* @param $title
* A string containing the current title.
* @return
* An integer containing the title state.
*/
function _region_manager_block_title_status($title) {
$title_status = 0; // Default title.
if ($title) {
$title_status++; // Disabled title.
if ($title != '') {
$title_status++; // Custom title.
}
}
return $title_status;
}