You are here

function context_reaction_block::options_form in Context 7.3

Same name and namespace in other branches
  1. 6.3 plugins/context_reaction_block.inc \context_reaction_block::options_form()
  2. 6 plugins/context_reaction_block.inc \context_reaction_block::options_form()

Options form.

Overrides context_reaction::options_form

1 call to context_reaction_block::options_form()
context_layouts_reaction_block::options_form in context_layouts/plugins/context_layouts_reaction_block.inc
Override of options form.
1 method overrides context_reaction_block::options_form()
context_layouts_reaction_block::options_form in context_layouts/plugins/context_layouts_reaction_block.inc
Override of options form.

File

plugins/context_reaction_block.inc, line 10

Class

context_reaction_block
Expose blocks as context reactions.

Code

function options_form($context) {

  // Rebuild the block info cache if necessary.
  $this
    ->get_blocks(NULL, NULL, $this
    ->rebuild_needed());
  $this
    ->rebuild_needed(FALSE);
  $theme_key = variable_get('theme_default', 'garland');
  $weight_delta = $this
    ->max_block_weight();
  $form = array(
    '#tree' => TRUE,
    '#theme' => 'context_block_form',
    'max_block_weight' => array(
      '#value' => $weight_delta,
      '#type' => 'value',
    ),
    'state' => array(
      '#type' => 'hidden',
      '#attributes' => array(
        'class' => 'context-blockform-state',
      ),
    ),
  );

  /**
   * Selector.
   */
  $modules = module_list();
  $form['selector'] = array(
    '#type' => 'item',
    '#tree' => TRUE,
    '#prefix' => '<div class="context-blockform-selector">',
    '#suffix' => '</div>',
  );
  foreach ($this
    ->get_blocks() as $block) {
    $group = isset($block->context_group) ? $block->context_group : $block->module;
    if (!isset($form['selector'][$group])) {
      $form['selector'][$group] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => isset($block->context_group) ? $block->context_group : $modules[$block->module],
      );
      $form['selector'][$group]['checkboxes'] = array(
        '#type' => 'checkboxes',
        '#options' => array(),
      );
    }
    $form['selector'][$group]['checkboxes']['#options'][$block->bid] = check_plain($block->info);
  }
  ksort($form['selector']);

  /**
   * Regions.
   */
  $form['blocks'] = array(
    '#tree' => TRUE,
    '#theme' => 'context_block_regions_form',
  );
  foreach ($this
    ->system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
    $form['blocks'][$region] = array(
      '#type' => 'item',
      '#title' => $label,
      '#tree' => TRUE,
    );
    foreach ($this
      ->get_blocks($region, $context) as $block) {
      if (!empty($block->context)) {
        $form['blocks'][$region][$block->bid] = array(
          '#value' => check_plain($block->info),
          '#weight' => $block->weight,
          '#type' => 'markup',
          '#tree' => TRUE,
          'weight' => array(
            '#type' => 'weight',
            '#delta' => $weight_delta,
            '#default_value' => $block->weight,
          ),
        );
      }
    }
  }
  return $form;
}