You are here

function ddblock_add_instance_form in Dynamic display block 7

Same name and namespace in other branches
  1. 6 ddblock.module \ddblock_add_instance_form()

form to add a dynamic display block instance.

1 string reference to 'ddblock_add_instance_form'
ddblock_instances in ./ddblock.module
ddblock instances.

File

./ddblock.module, line 2546
Enables your site to display dynamic content in a block.

Code

function ddblock_add_instance_form($form, $form_state) {
  $form = array();
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Instance Title'),
    '#maxlength' => 256,
    '#required' => TRUE,
  );

  // Turn $blocks into form options of block types.
  $options = array();

  //get possible content types from settings.
  $block_types = variable_get('ddblock_blocks', array());
  foreach ($block_types as $value) {
    if ($value) {

      //$option[0]  contains module name, $option[1]  contains delta, $option[2]  contains block title,
      $option = explode(':', $value);

      //If the block title contains colons, the value in $option[2] would

      //be incorrect. Any array elements > 3 also belong in the title, so if

      //they exist, loop through them and add them to the block title.
      $block_title = $option[2];
      for ($i = 3; $i < count($option); $i++) {
        $block_title .= ":" . $option[$i];
      }
      $options[$option[0] . ':' . $option[1]] = $option[0] . ' - ' . $block_title;
    }
  }
  $form['block'] = array(
    '#type' => 'select',
    '#title' => t('Block type'),
    '#options' => $options,
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add Instance'),
  );
  return $form;
}