function block_user in Drupal 5
Same name and namespace in other branches
- 4 modules/block.module \block_user()
- 6 modules/block/block.module \block_user()
Implementation of hook_user().
Allow users to decide which custom blocks to display when they visit the site.
File
- modules/
block/ block.module, line 591 - Controls the boxes that are displayed around the main content.
Code
function block_user($type, $edit, &$account, $category = NULL) {
switch ($type) {
case 'form':
if ($category == 'account') {
$rids = array_keys($account->roles);
$placeholders = implode(',', array_fill(0, count($rids), '%d'));
$result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN ({$placeholders}) OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
$form['block'] = array(
'#type' => 'fieldset',
'#title' => t('Block configuration'),
'#weight' => 3,
'#collapsible' => TRUE,
'#tree' => TRUE,
);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
$return = TRUE;
$form['block'][$block->module][$block->delta] = array(
'#type' => 'checkbox',
'#title' => check_plain($data[$block->delta]['info']),
'#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : $block->custom == 1,
);
}
}
if ($return) {
return $form;
}
}
break;
case 'validate':
if (!$edit['block']) {
$edit['block'] = array();
}
return $edit;
}
}