You are here

function redis_settings_form_submit_clean_values in Redis 7.2

Same name and namespace in other branches
  1. 7.3 redis.admin.inc \redis_settings_form_submit_clean_values()

Deep clean of $form_state values.

1 string reference to 'redis_settings_form_submit_clean_values'
redis_settings_form in ./redis.admin.inc
Main settings and review administration screen.

File

./redis.admin.inc, line 75
Redis module administration pages.

Code

function redis_settings_form_submit_clean_values($form, &$form_state) {
  $string_values = array(
    'redis_client_host',
    'redis_client_interface',
  );
  foreach ($string_values as $name) {

    // Empty check is sufficient to verify that the field is indeed empty.
    if (empty($form_state['values'][$name])) {

      // Using unset() will keep the key in the array, with an associated NULL
      // value. While this wouldn't really matter, it's safer to remove it so
      // that system_settings_form_submit() won't find it and attempt to save
      // it.
      $form_state['values'] = array_diff_key($form_state['values'], array(
        $name => NULL,
      ));
      variable_del($name);
    }
  }
  $numeric_values = array(
    'redis_client_base',
    'redis_client_port',
  );
  foreach ($numeric_values as $name) {

    // Numeric values can be both of NULL or 0 (NULL meaning the value is not
    // not set and the client will use the default, while 0 has a business
    // meaning and should be kept as is).
    if ('0' !== $form_state['values'][$name] && empty($form_state['values'][$name])) {
      $form_state['values'] = array_diff_key($form_state['values'], array(
        $name => NULL,
      ));
      variable_del($name);
    }
    else {
      $form_state['values'][$name] = (int) $form_state['values'][$name];
    }
  }
}