You are here

function homebox_admin_display_form in Homebox 6.3

Same name and namespace in other branches
  1. 6 homebox.admin.inc \homebox_admin_display_form()
  2. 6.2 homebox.admin.inc \homebox_admin_display_form()
  3. 7.3 homebox.admin.inc \homebox_admin_display_form()
  4. 7.2 homebox.admin.inc \homebox_admin_display_form()

Generate main blocks administration form.

1 string reference to 'homebox_admin_display_form'
homebox_layout in ./homebox.admin.inc
Form builder function for module settings.

File

./homebox.admin.inc, line 422
Homebox admin file, takes care admin interface for homebox

Code

function homebox_admin_display_form(&$form_state, $blocks, $page, $theme = NULL) {
  global $theme_key, $custom_theme;

  // Add CSS
  drupal_add_css(drupal_get_path('module', 'block') . '/block.css', 'module', 'all', FALSE);

  // If non-default theme configuration has been selected, set the custom theme.
  $custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland');
  $columns = homebox_named_columns($page->settings['regions']);
  $block_regions = $columns + array(
    HOMEBOX_REGION_NONE => '<' . t('none') . '>',
  );

  // Weights range from -delta to +delta, so delta should be at least half
  // of the amount of blocks present. This makes sure all blocks in the same
  // region get an unique weight.
  $weight_delta = round(count($blocks) / 2);

  // Build form tree
  $form = array(
    '#tree' => TRUE,
  );

  // Iterate on each block
  foreach ($blocks as $i => $block) {
    $key = $block['module'] . '_' . $block['delta'];
    $form[$key]['module'] = array(
      '#type' => 'value',
      '#value' => $block['module'],
    );
    $form[$key]['delta'] = array(
      '#type' => 'value',
      '#value' => $block['delta'],
    );
    $form[$key]['info'] = array(
      '#value' => check_plain($block['info']),
    );
    $form[$key]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $block['weight'],
      '#delta' => $weight_delta,
    );

    // Get default region/column for block
    $column = $page->settings['blocks'][$key]['region'];

    // If not set assign to <none>
    $column = $column != 0 ? $column : HOMEBOX_REGION_NONE;
    $form[$key]['region'] = array(
      '#type' => 'select',
      '#default_value' => $column,
      '#options' => $block_regions,
    );
    $form[$key]['title'] = array(
      '#type' => 'textfield',
      '#default_value' => $block['title'],
      '#size' => 15,
    );
    $form[$key]['status'] = array(
      '#type' => 'checkbox',
      '#default_value' => $block['status'],
    );
    $form[$key]['open'] = array(
      '#type' => 'checkbox',
      '#default_value' => $block['open'],
    );
    $form[$key]['movable'] = array(
      '#type' => 'checkbox',
      '#default_value' => $block['movable'],
    );
    $form[$key]['closable'] = array(
      '#type' => 'checkbox',
      '#default_value' => $block['closable'],
    );
    $form[$key]['bid'] = array(
      '#type' => 'value',
      '#value' => $block['bid'],
    );
  }
  $form['name'] = array(
    '#type' => 'value',
    '#value' => $page->name,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save blocks'),
  );
  return $form;
}