You are here

function blockcache_alter_save_settings in Block Cache Alter 6

Same name and namespace in other branches
  1. 7 blockcache_alter.module \blockcache_alter_save_settings()

Submit callback. Saves block configuration and cache settings per block. This module takes over from block_admin_configure_submit() so we can decide what to clear from cache.

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 232
Block Cache alter.

Code

function blockcache_alter_save_settings($form, &$form_state) {
  if (!form_get_errors()) {
    db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']);
    db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
    foreach (array_filter($form_state['values']['roles']) as $rid) {
      db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
    }
    module_invoke($form_state['values']['module'], 'block', 'save', $form_state['values']['delta'], $form_state['values']);
    drupal_set_message(t('The block configuration has been saved.'));

    // Save block cache settings.
    db_query("DELETE FROM {blockcache_alter} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
    db_query("INSERT INTO {blockcache_alter} (module, delta, cache) VALUES ('%s', '%s', %d)", $form_state['values']['module'], $form_state['values']['delta'], $form_state['values']['cache_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.
      db_query("DELETE FROM {variable} WHERE name IN ('%s', '%s', '%s')", 'bc_life_' . $form['module']['#value'] . '_' . $form['delta']['#value'], 'bc_refresh_' . $form['module']['#value'] . '_' . $form['delta']['#value'], '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']);
      }
    }

    // Redirect.
    $form_state['redirect'] = 'admin/build/block';
    return;
  }
}