You are here

function advagg_relocate_admin_settings_form_submit in Advanced CSS/JS Aggregation 7.2

Submit callback, clear out the advagg cache bin.

Also process the advagg_relocate_css_file_settings variable.

Related topics

1 string reference to 'advagg_relocate_admin_settings_form_submit'
advagg_relocate_admin_settings_form in advagg_relocate/advagg_relocate.admin.inc
Form builder; Configure advagg settings.

File

advagg_relocate/advagg_relocate.admin.inc, line 400
Admin page callbacks for the advagg relocate module.

Code

function advagg_relocate_admin_settings_form_submit($form, &$form_state) {

  // Work around PHP bug with $_POST not containing all the data.
  $alt_post = array();
  $input = rawurldecode(file_get_contents('php://input'));
  parse_str($input, $alt_post);
  $alt_post = drupal_json_decode(str_replace(' ', '+', drupal_json_encode($alt_post)));
  $diff = advagg_diff_multi($_POST, $alt_post);
  if (!empty($diff)) {
    foreach ($diff as $k => $v) {
      if (isset($form_state['values'][$k])) {
        $form_state['values'][$k] = $v;
      }
    }
  }

  // Reset this form to defaults or recommended values; also show what changed.
  advagg_set_admin_form_defaults_recommended($form_state, 'advagg_relocate_admin_mode');

  // Get settings that start with advagg_relocate_css_file_settings.
  if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50600) {
    $vars = array_filter($form_state['values'], '_advagg_relocate_admin_is_css_file_settings', ARRAY_FILTER_USE_KEY);
  }
  else {
    $vars = array_intersect_key($form_state['values'], array_flip(array_filter(array_keys($form_state['values']), '_advagg_relocate_admin_is_css_file_settings')));
  }

  // Unset found values.
  foreach ($vars as $key => $value) {
    if (isset($form_state['values'][$key])) {
      unset($form_state['values'][$key]);
    }

    // If all is set, remove sub options for that file.
    if (strpos($key, 'advagg_relocate_css_file_settings_all_') === 0 && !empty($value)) {
      $sub_key = str_replace('advagg_relocate_css_file_settings_all_', 'advagg_relocate_css_file_settings_', $key);
      if (isset($vars[$sub_key])) {
        unset($vars[$sub_key]);
      }
    }
  }

  // Save under one variable.
  $saved_values = array();
  foreach ($vars as $key => $value) {
    $key = str_replace('advagg_relocate_css_file_settings_all_', 'all:', $key);
    $key = str_replace('advagg_relocate_css_file_settings_', '', $key);
    $saved_values[$key] = $value;
  }
  $form_state['values']['advagg_relocate_css_file_settings'] = $saved_values;

  // Clear caches.
  advagg_cache_clear_admin_submit();
}