function space_customizer_block::form in Spaces 6
Same name and namespace in other branches
- 6.2 spaces.spaces.inc \space_customizer_block::form()
Implementation of form().
Overrides space_customizer::form
File
- ./
spaces.module, line 723
Class
- space_customizer_block
- Customizer for feature blocks.
Code
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;
}