You are here

function block_user in Drupal 4

Same name and namespace in other branches
  1. 5 modules/block/block.module \block_user()
  2. 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.module, line 556
Controls the boxes that are displayed around the main content.

Code

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;
  }
}