function multiblock_add_form_submit in MultiBlock 7
Same name and namespace in other branches
- 5 multiblock.module \multiblock_add_form_submit()
- 6 multiblock.module \multiblock_add_form_submit()
Add block instance to database from "Add Block Instance" form.
File
- ./
multiblock.module, line 329 - Enhances the block API, as provided by D7 Core.
Code
function multiblock_add_form_submit($form, &$form_state) {
if (isset($form_state['values']['instance'])) {
$num_updated = db_update('multiblock')
->fields(array(
'title' => $form_state['values']['title'],
))
->condition('delta', $form_state['values']['instance'], '=')
->execute();
$block = multiblock_get_block($form_state['values']['instance'], TRUE);
$cache = db_query('SELECT cache FROM {block} WHERE module = :module AND delta = :orig_delta', array(
":module" => $block->module,
":orig_delta" => $block->orig_delta,
))
->fetchField();
if ($cache) {
db_query('UPDATE {block} SET cache = :cache WHERE delta = :delta AND module = :multiblock', array(
':cache' => $cache,
':delta' => $block->delta,
':multiblock' => 'multiblock',
));
}
$form_state['redirect'] = 'admin/structure/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.
$block_info = module_invoke($orig_block['module'], 'block_info');
$mb_enabled = (int) (!empty($block_info[$orig_block['delta']]['mb_enabled']) && $block_info[$orig_block['delta']]['mb_enabled'] == TRUE);
// 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'],
)));
}