function blockcache_alter_save_settings in Block Cache Alter 7
Same name and namespace in other branches
- 6 blockcache_alter.module \blockcache_alter_save_settings()
Submit callback. Saves cache settings per block.
1 string reference to 'blockcache_alter_save_settings'
- blockcache_alter_form_alter in ./
blockcache_alter.module - Implementation of hook_form_alter().
File
- ./
blockcache_alter.module, line 215 - Block cache alter module.
Code
function blockcache_alter_save_settings($form, &$form_state) {
$bids = db_select('block', 'b')
->fields('b', array(
'bid',
))
->condition('module', $form['module']['#value'])
->condition('delta', $form['delta']['#value'])
->execute()
->fetchCol();
$blockcache_alter = db_select('blockcache_alter', 'b')
->fields('b', array(
'bid',
))
->condition('b.bid', $bids)
->execute()
->fetchCol();
$block = new StdClass();
$block->module = $form_state['values']['module'];
$block->delta = $form_state['values']['delta'];
$block->cache = $form_state['values']['cache_block'];
foreach ($bids as $bid) {
$block->bid = $bid;
drupal_write_record('block', $block, array(
'bid',
));
if (in_array($bid, $blockcache_alter)) {
drupal_write_record('blockcache_alter', $block, array(
'bid',
));
}
else {
drupal_write_record('blockcache_alter', $block);
}
}
// Core patch applied or not.
$core_patch = variable_get('bca_corepatch', 0);
// Cache clearing
switch ($form_state['values']['cache_block_clear']) {
case '1':
cache_clear_all($form_state['values']['module'] . ':' . $form_state['values']['delta'], 'cache_block', TRUE);
break;
case '2':
cache_clear_all();
break;
}
// Store extra variables if core patch is applied.
if ($core_patch == TRUE) {
// Remove old variables to avoid clutter in the variable table.
variable_del('bc_life_' . $form['module']['#value'] . '_' . $form['delta']['#value']);
variable_del('bc_refresh_' . $form['module']['#value'] . '_' . $form['delta']['#value']);
variable_del('bc_relate_' . $form['module']['#value'] . '_' . $form['delta']['#value']);
// Remember block expire time or refresh actions for the future.
if (!empty($form_state['values']['bc_life'])) {
variable_set('bc_life_' . $form['module']['#value'] . '_' . $form['delta']['#value'], $form_state['values']['bc_life']);
}
else {
variable_set('bc_refresh_' . $form['module']['#value'] . '_' . $form['delta']['#value'], $form_state['values']['bc_refresh']);
variable_set('bc_relate_' . $form['module']['#value'] . '_' . $form['delta']['#value'], $form_state['values']['bc_relate']);
}
}
}