function twitter_block_add_block_form_submit in Twitter Block 7
Same name and namespace in other branches
- 7.2 twitter_block.admin.inc \twitter_block_add_block_form_submit()
Form submission handler for twitter_block_add_block_form().
Saves the new custom Twitter block.
See also
twitter_block_add_block_form()
twitter_block_add_block_form_validate()
1 string reference to 'twitter_block_add_block_form_submit'
- twitter_block_add_block_form in ./
twitter_block.admin.inc - Form constructor for the add block form.
File
- ./
twitter_block.admin.inc, line 53 - Admin page callbacks for the Twitter Block module.
Code
function twitter_block_add_block_form_submit($form, &$form_state) {
// Save the block configuration
$delta = db_insert('twitter_block')
->fields(array(
'info' => $form_state['values']['info'],
'search_type' => $form_state['values']['search_type'],
'include_rts' => $form_state['values']['include_rts'],
'search_string' => $form_state['values']['search_string'],
'results_per_page' => $form_state['values']['results_per_page'],
'lang' => $form_state['values']['lang'],
))
->execute();
// Store block delta to allow other modules to work with new block
$form_state['values']['delta'] = $delta;
// Run the normal new block submission (borrowed from block_add_block_form_submit)
$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();
}
drupal_set_message(t('The block has been created.'));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
}