class space_customizer_block in Spaces 6
Same name and namespace in other branches
- 6.2 spaces.spaces.inc \space_customizer_block
Customizer for feature blocks.
Hierarchy
- class \space_customizer_block implements space_customizer
Expanded class hierarchy of space_customizer_block
File
- ./
spaces.module, line 716
View source
class space_customizer_block implements space_customizer {
var $name = 'Blocks';
/**
* Implementation of form().
*/
function form($space, $feature) {
$form = array(
'#theme' => 'spaces_block_customizer_settings_form',
'#tree' => TRUE,
);
$features = spaces_features();
$f = $features[$feature];
$customizer = !empty($space->customizer[$feature]['block']) ? $space->customizer[$feature]['block'] : array();
$info = array();
global $theme_key;
init_theme();
$regions = system_region_list($theme_key);
if (!empty($f->block)) {
foreach ($f->block as $block) {
// @TODO: remove this once context is less confused about itself.
$block = (array) $block;
$bid = "{$block['module']}-{$block['delta']}";
if (!empty($block['region'])) {
if (!isset($info[$block['module']])) {
$info[$block['module']] = module_invoke($block['module'], 'block', 'list');
// If the block is provided by Views, doctor the info to strip out the
// view name leaving only the block's display name.
if ($block['module'] == 'views') {
foreach ($info[$block['module']] as $k => $v) {
$viewname = strpos($v['info'], ':');
if ($viewname !== FALSE) {
$v['info'] = substr($v['info'], $viewname + 2);
$info[$block['module']][$k] = $v;
}
}
}
}
// Sanity check that this region exists
$region = $block['region'];
if (!empty($regions[$region])) {
if (!isset($form[$region])) {
$form[$region] = array(
'#title' => $regions[$region],
'#tree' => TRUE,
);
}
$block_details = module_invoke($block['module'], 'block', 'view', $block['delta']);
if (!empty($info[$block['module']][$block['delta']])) {
$default_weight = isset($block['weight']) ? $block['weight'] : 0;
$default_status = isset($block['status']) ? $block['status'] : 1;
$default_subject = !empty($block_details['subject']) ? $block_details['subject'] : '';
$form[$region][$bid] = array(
'#tree' => TRUE,
'#weight' => isset($customizer[$region][$bid]['weight']) ? $customizer[$region][$bid]['weight'] : $default_weight,
);
$form[$region][$bid]['weight'] = array(
'#type' => 'weight',
'#delta' => 25,
'#default_value' => isset($customizer[$region][$bid]['weight']) ? $customizer[$region][$bid]['weight'] : $default_weight,
);
$form[$region][$bid]['status'] = array(
'#type' => 'checkbox',
'#default_value' => isset($customizer[$region][$bid]['status']) ? $customizer[$region][$bid]['status'] : $default_status,
);
// If the block subject is empty, it's likely to be for a good reason
// e.g. the subject is generated dynamically or the block is slimmed
// down. Let's respect that.
if (!empty($default_subject)) {
$form[$region][$bid]['subject'] = array(
'#type' => 'textfield',
'#default_value' => !empty($customizer[$region][$bid]['subject']) ? $customizer[$region][$bid]['subject'] : $default_subject,
'#description' => $info[$block['module']][$block['delta']]['info'],
);
}
else {
$form[$region][$bid]['subject'] = array(
'#type' => 'markup',
'#value' => $info[$block['module']][$block['delta']]['info'],
);
}
// Pass default values to the submit handler so it can omit them.
$form[$region][$bid]['default_weight'] = array(
'#type' => 'value',
'#value' => $default_weight,
);
$form[$region][$bid]['default_status'] = array(
'#type' => 'value',
'#value' => $default_status,
);
$form[$region][$bid]['default_subject'] = array(
'#type' => 'value',
'#value' => $default_subject,
);
}
}
}
}
}
return $form;
}
/**
* Implementation of validate().
*/
function validate($space, $feature, $value) {
return;
}
/**
* Implementation of submit().
* Iterate through and only record the aspects of each block that have been customized.
*/
function submit($space, $feature, $value) {
foreach ($value as $region => $blocks) {
foreach ($blocks as $bid => $block) {
foreach (array(
'weight',
'status',
'subject',
) as $key) {
if (isset($block[$key])) {
if ($block[$key] == $block["default_{$key}"]) {
unset($value[$region][$bid][$key]);
}
}
unset($value[$region][$bid]["default_{$key}"]);
}
}
}
return $value;
}
/**
* Implementation of customize().
*/
function customize($space, $feature, &$block = NULL) {
// Unset disabled blocks and change weights based on customizer settings. See spaces_context_active_contexts_alter.
if (!empty($space->customizer[$feature]['block'])) {
$customizer = $space->customizer[$feature]['block'];
foreach ($block as $key => $b) {
// @TODO: remove this once context is less confused about itself.
$b = (array) $b;
$block[$key] = (array) $block[$key];
$bid = "{$b['module']}-{$b['delta']}";
// If the block is not enabled, yank it out of the blocks array
if (!empty($customizer[$b['region']][$bid])) {
if (isset($customizer[$b['region']][$bid]['status']) && $customizer[$b['region']][$bid]['status'] === 0) {
unset($block[$key]);
}
if (isset($customizer[$b['region']][$bid]['weight'])) {
$block[$key]['weight'] = $customizer[$b['region']][$bid]['weight'];
}
}
}
}
}
/**
* Additional method: customize_subject() for customizing a block subject.
*/
function customize_subject($space, $feature, &$block) {
if (!empty($space->customizer[$feature]['block'])) {
$customizer = $space->customizer[$feature]['block'];
$bid = "{$block->module}-{$block->delta}";
if (!empty($customizer[$block->region][$bid]['subject'])) {
$block->subject = $customizer[$block->region][$bid]['subject'];
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
space_customizer_block:: |
property | |||
space_customizer_block:: |
function |
Implementation of customize(). Overrides space_customizer:: |
||
space_customizer_block:: |
function | Additional method: customize_subject() for customizing a block subject. | ||
space_customizer_block:: |
function |
Implementation of form(). Overrides space_customizer:: |
||
space_customizer_block:: |
function |
Implementation of submit().
Iterate through and only record the aspects of each block that have been customized. Overrides space_customizer:: |
||
space_customizer_block:: |
function |
Implementation of validate(). Overrides space_customizer:: |