function imageblock_add_block_form_submit in Image Block 7
Same name and namespace in other branches
- 6 imageblock.module \imageblock_add_block_form_submit()
Form submission handler for the add image block form.
Saves the new custom image block.
See also
block_add_block_form_validate()
File
- ./
imageblock.admin.inc, line 66
Code
function imageblock_add_block_form_submit($form, &$form_state) {
$delta = db_insert('imageblock')
->fields(array(
'body' => $form_state['values']['body']['value'],
'info' => $form_state['values']['info'],
'format' => $form_state['values']['body']['format'],
))
->execute();
// Store block delta to allow other modules to work with new block.
$form_state['values']['delta'] = $delta;
$query = db_insert('block')
->fields(array(
'visibility',
'pages',
'custom',
'title',
'module',
'theme',
'status',
'weight',
'delta',
'cache',
));
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
$query
->values(array(
'visibility' => (int) $form_state['values']['visibility'],
'pages' => trim($form_state['values']['pages']),
'custom' => (int) $form_state['values']['custom'],
'title' => $form_state['values']['title'],
'module' => $form_state['values']['module'],
'theme' => $theme->name,
'status' => 0,
'weight' => 0,
'delta' => $delta,
'cache' => DRUPAL_NO_CACHE,
));
}
}
$query
->execute();
$query = db_insert('block_role')
->fields(array(
'rid',
'module',
'delta',
));
foreach (array_filter($form_state['values']['roles']) as $rid) {
$query
->values(array(
'rid' => $rid,
'module' => $form_state['values']['module'],
'delta' => $delta,
));
}
$query
->execute();
// Store regions per theme for this block
foreach ($form_state['values']['regions'] as $theme => $region) {
db_merge('block')
->key(array(
'theme' => $theme,
'delta' => $delta,
'module' => $form_state['values']['module'],
))
->fields(array(
'region' => $region == BLOCK_REGION_NONE ? '' : $region,
'pages' => trim($form_state['values']['pages']),
'status' => (int) ($region != BLOCK_REGION_NONE),
))
->execute();
}
imageblock_block_save($delta, $form_state['values']);
drupal_set_message(t('The image block has been created.'));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
}