function menu_block_add_block_form_submit in Menu Block 7.3
Same name and namespace in other branches
- 5.2 menu_block.admin.inc \menu_block_add_block_form_submit()
- 6.2 menu_block.admin.inc \menu_block_add_block_form_submit()
- 7.2 menu_block.admin.inc \menu_block_add_block_form_submit()
Save the new menu block.
1 string reference to 'menu_block_add_block_form_submit'
- menu_block_add_block_form in ./
menu_block.admin.inc - Menu callback: display the menu block addition form.
File
- ./
menu_block.admin.inc, line 31 - Provides infrequently used functions and hooks for menu_block.
Code
function menu_block_add_block_form_submit($form, &$form_state) {
// Determine the delta of the new block.
$block_ids = variable_get('menu_block_ids', array());
$delta = empty($block_ids) ? 1 : max($block_ids) + 1;
$form_state['values']['delta'] = $delta;
// Save the new array of blocks IDs.
$block_ids[] = $delta;
variable_set('menu_block_ids', $block_ids);
// Save the block configuration.
menu_block_block_save($delta, $form_state['values']);
// 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',
'region',
'status',
'weight',
'delta',
'cache',
));
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
$region = !empty($form_state['values']['regions'][$theme->name]) ? $form_state['values']['regions'][$theme->name] : BLOCK_REGION_NONE;
$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,
'region' => $region == BLOCK_REGION_NONE ? '' : $region,
'status' => 0,
'status' => (int) ($region != BLOCK_REGION_NONE),
'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();
drupal_set_message(t('The block has been created.'));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
}