You are here

function homebox_add_block in Homebox 7.2

Same name and namespace in other branches
  1. 6.3 homebox.module \homebox_add_block()
  2. 6.2 homebox.module \homebox_add_block()
  3. 7.3 homebox.module \homebox_add_block()

Add a custom block to a user's page.

1 string reference to 'homebox_add_block'
homebox_menu in ./homebox.module
Implements hook_menu().

File

./homebox.module, line 1252
Homebox main file, takes care of global functions settings constants, etc.

Code

function homebox_add_block($page, $module, $delta) {
  $user_blocks = _homebox_get_user_settings($page, TRUE);

  // Build custom block
  $block = array(
    'module' => $module,
    'delta' => $delta,
    'title' => '',
    'open' => 1,
    'color' => 'default',
    'status' => 1,
    'region' => 1,
    'movable' => 1,
    'closable' => 1,
  );
  if (module_hook($block['module'], 'homebox_block_keys')) {
    foreach (module_invoke($module, 'homebox_block_keys', (object) $block) as $key) {
      if (isset($_REQUEST[$key])) {
        $block[$key] = $_REQUEST[$key];
      }
    }
  }

  // Add custom block to user's blocks
  $key = $block['module'] . '_' . $block['delta'];
  $id = 1;
  if (isset($user_blocks[$key])) {
    while (isset($user_blocks[$key . '-' . $id])) {
      $id += 1;
    }
    $key .= '-' . $id;
  }
  $user_blocks = array_merge(array(
    $key => $block,
  ), $user_blocks);
  _homebox_save_user_settings($page, $user_blocks);
  drupal_goto(homebox_get_path($page));
}