Form submission handler for block_admin_configure().
block_admin_configure_validate()
function block_admin_configure_submit($form, &$form_state) {
if (!form_get_errors()) {
$transaction = db_transaction();
try {
db_update('block')
->fields(array(
'visibility' => (int) $form_state['values']['visibility'],
'pages' => trim($form_state['values']['pages']),
'custom' => (int) $form_state['values']['custom'],
'title' => $form_state['values']['title'],
))
->condition('module', $form_state['values']['module'])
->condition('delta', $form_state['values']['delta'])
->execute();
db_delete('block_role')
->condition('module', $form_state['values']['module'])
->condition('delta', $form_state['values']['delta'])
->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' => $form_state['values']['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' => $form_state['values']['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();
}
// Update the block visibility settings if we have settings to store
// for the existing languages.
if (module_exists('language') && isset($form_state['values']['langcodes'])) {
db_delete('block_language')
->condition('module', $form_state['values']['module'])
->condition('delta', $form_state['values']['delta'])
->execute();
$query = db_insert('block_language')
->fields(array(
'type',
'langcode',
'module',
'delta',
));
foreach (array_filter($form_state['values']['langcodes']) as $langcode) {
$query
->values(array(
'type' => $form_state['values']['language_type'],
'langcode' => $langcode,
'module' => $form_state['values']['module'],
'delta' => $form_state['values']['delta'],
));
}
$query
->execute();
}
module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('block', $e);
throw $e;
}
drupal_set_message(t('The block configuration has been saved.'));
cache_invalidate_tags(array(
'content' => TRUE,
));
$form_state['redirect'] = 'admin/structure/block';
}
}