You are here

function multiblock_add_form_submit in MultiBlock 6

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

Add block instance to database from "Add Block Instance" form.

File

./multiblock.module, line 246

Code

function multiblock_add_form_submit($form, &$form_state) {
  if (isset($form_state['values']['instance'])) {
    db_query("UPDATE {multiblock} SET title='%s' WHERE delta=%d", $form_state['values']['title'], $form_state['values']['instance']);
    $form_state['redirect'] = 'admin/build/block/instances';
    return;
  }

  // Get the original block info.
  $orig_block = multiblock_blockinfo_from_form($form_state['values']['block']);

  // Check whether this module is multiblock enabled.
  $mb_enabled = (int) (module_invoke($orig_block['module'], 'block', 'mb_enabled') == 'mb_enabled');

  // Create block instance information.
  $orig_block = (object) $orig_block;
  $instance = (object) array(
    'title' => $form_state['values']['title'],
    'mb_enabled' => $mb_enabled,
  );

  // Add the block instance.
  multiblock_add($orig_block, $instance);
  drupal_set_message(t('Block instance %instance created.', array(
    '%instance' => $form_state['values']['title'],
  )));
}