You are here

function multiblock_add_form in MultiBlock 6

Same name and namespace in other branches
  1. 5 multiblock.module \multiblock_add_form()
  2. 7 multiblock.module \multiblock_add_form()

"Add Instance" form.

1 string reference to 'multiblock_add_form'
multiblock_general in ./multiblock.module
Page callback for the "Manage Block Instances page".

File

./multiblock.module, line 126

Code

function multiblock_add_form(&$form_state, $blocks, $update = NULL) {
  $form = array();
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Instance Title'),
    '#maxlength' => 256,
    '#required' => TRUE,
    '#default_value' => $update ? $update->title : NULL,
  );
  if ($update) {
    $form['instance'] = array(
      '#type' => 'value',
      '#value' => $update->delta,
    );
  }
  else {

    // Turn $blocks into form options of block types.
    // Remember we need the module and delta to be able to tell what kind of
    // blocks we're talking about.
    $options = array();
    foreach ($blocks as $block) {

      // Don't include multiblock module blocks in the list.
      if ($block['module'] != 'multiblock') {
        $options[$block['module'] . '***MB***' . $block['delta']] = $block['info'];
      }
    }
    $form['block'] = array(
      '#type' => 'select',
      '#title' => t('Block type'),
      '#options' => $options,
      '#required' => TRUE,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}