function block_admin_display_form

Form constructor for the main block administration form.

Parameters

$blocks: An array of blocks, as returned by block_admin_display_prepare_blocks().

$theme: A string representing the name of the theme to edit blocks for.

$block_regions: (optional) An array of regions in which the blocks will be allowed to be placed. Defaults to all visible regions for the theme whose blocks are being configured. In all cases, a dummy region for disabled blocks will also be displayed.

Return value

An array representing the form definition.

See also

block_admin_display_form_submit()

Related topics

1 string reference to 'block_admin_display_form'
block_admin_display in drupal/core/modules/block/block.admin.inc
Page callback: Shows the block administration page.

File

drupal/core/modules/block/block.admin.inc, line 82
Admin page callbacks for the block module.

Code

function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL) {
  $path = drupal_get_path('module', 'block');
  $form['#attached']['css'][] = $path . '/block.admin.css';
  $form['#attached']['library'][] = array(
    'system',
    'drupal.tableheader',
  );
  $form['#attached']['library'][] = array(
    'block',
    'drupal.block',
  );

  // Get a list of block regions if one was not provided.
  if (!isset($block_regions)) {
    $block_regions = system_region_list($theme, REGIONS_VISIBLE);
  }

  // Add a last region for disabled blocks.
  $block_regions_with_disabled = $block_regions + array(
    BLOCK_REGION_NONE => BLOCK_REGION_NONE,
  );
  foreach ($block_regions_with_disabled as $region => $title) {
    $form['#attached']['drupal_add_tabledrag'][] = array(
      'blocks',
      'match',
      'sibling',
      'block-region-select',
      'block-region-' . $region,
      NULL,
      FALSE,
    );
    $form['#attached']['drupal_add_tabledrag'][] = array(
      'blocks',
      'order',
      'sibling',
      'block-weight',
      'block-weight-' . $region,
    );
  }

  // 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 the form tree.
  $form['edited_theme'] = array(
    '#type' => 'value',
    '#value' => $theme,
  );
  $form['block_regions'] = array(
    '#type' => 'value',
    '#value' => $block_regions_with_disabled,
  );
  $form['blocks'] = array();
  $form['#tree'] = TRUE;
  foreach ($blocks as $i => $block) {
    $key = $block['module'] . '_' . $block['delta'];
    $form['blocks'][$key]['module'] = array(
      '#type' => 'value',
      '#value' => $block['module'],
    );
    $form['blocks'][$key]['delta'] = array(
      '#type' => 'value',
      '#value' => $block['delta'],
    );
    $form['blocks'][$key]['info'] = array(
      '#markup' => check_plain($block['info']),
    );
    $form['blocks'][$key]['theme'] = array(
      '#type' => 'hidden',
      '#value' => $theme,
    );
    $form['blocks'][$key]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $block['weight'],
      '#delta' => $weight_delta,
      '#title_display' => 'invisible',
      '#title' => t('Weight for @block block', array(
        '@block' => $block['info'],
      )),
    );
    $form['blocks'][$key]['region'] = array(
      '#type' => 'select',
      '#default_value' => $block['region'] != BLOCK_REGION_NONE ? $block['region'] : NULL,
      '#empty_value' => BLOCK_REGION_NONE,
      '#title_display' => 'invisible',
      '#title' => t('Region for @block block', array(
        '@block' => $block['info'],
      )),
      '#options' => $block_regions,
    );
    $links['configure'] = array(
      'title' => t('configure'),
      'href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure',
    );
    if ($block['module'] == 'block') {
      $links['delete'] = array(
        'title' => t('delete'),
        'href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/delete',
      );
    }
    $form['blocks'][$key]['operations'] = array(
      '#type' => 'operations',
      '#links' => $links,
    );
  }

  // Do not allow disabling the main system content block when it is present.
  if (isset($form['blocks']['system_main']['region'])) {
    $form['blocks']['system_main']['region']['#required'] = TRUE;
  }
  $form['actions'] = array(
    '#tree' => FALSE,
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save blocks'),
  );
  return $form;
}