| Versions | |
|---|---|
| 4.7 | block_user($type, $edit, & |
| 5 – 6 | block_user($type, $edit, &$account, $category = NULL) |
Implementation of hook_user().
Allow users to decide which custom blocks to display when they visit the site.
modules/
<?php
function block_user($type, $edit, &$user, $category = NULL) {
switch ($type) {
case 'form':
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE status = 1 AND custom != 0 ORDER BY weight, module, delta');
$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' => $data[$block->delta]['info'],
'#default_value' => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1),
);
}
}
if ($return) {
return $form;
}
}
break;
case 'validate':
if (!$edit['block']) {
$edit['block'] = array();
}
return $edit;
}
}
?>