You are here

function stringoverrides_admin_submit in String Overrides 6

Same name and namespace in other branches
  1. 5 stringoverrides.admin.inc \stringoverrides_admin_submit()
  2. 7 stringoverrides.admin.inc \stringoverrides_admin_submit()

Triggered when the user submits the administration page

File

./stringoverrides.admin.inc, line 82
Admin page callbacks for the String Overrides module.

Code

function stringoverrides_admin_submit($form, &$form_state) {

  // Format the words correctly so that they're put into the database correctly
  $words = array(
    FALSE => array(),
    TRUE => array(),
  );
  foreach ($form_state['values']['string'] as $index => $string) {
    if (!empty($string['original'])) {

      // Get rid of carriage returns.
      list($orig, $replace) = str_replace("\r", '', array(
        $string['original'],
        $string['replacement'],
      ));
      $words[$string['enabled']][$orig] = $replace;
    }
  }

  // Save into the correct language definition
  $lang = $form['lang']['#value'];
  if (empty($lang)) {
    $language = language_default();
    $lang = $language->language;
  }
  variable_set('locale_custom_strings_' . $lang, $words[1]);

  // Save the values and display a message to the user depend
  switch ($form_state['values']['op']) {
    case t('Save configuration'):
      variable_set('locale_custom_disabled_strings_' . $lang, $words[0]);
      drupal_set_message(t('Your changes have been saved.'));
      break;
    case t('Remove disabled strings'):
      variable_del('locale_custom_disabled_strings_' . $lang);
      drupal_set_message(t('The disabled strings have been removed.'));
      break;
  }
}