You are here

function stringoverrides_admin in String Overrides 6

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

Menu callback for the String Overrides module to display its administration

2 string references to 'stringoverrides_admin'
stringoverrides_js in ./stringoverrides.admin.inc
Menu callback for the String Overrides module to display a new string override
stringoverrides_menu in ./stringoverrides.module
Implementation of hook_menu()

File

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

Code

function stringoverrides_admin($form_state = NULL, $lang = NULL) {

  // See which language we're modifying
  if (empty($lang)) {
    $language = language_default();
    $lang = $language->language;
  }

  // Setup the form
  $form = array(
    '#cache' => TRUE,
  );
  $form['lang'] = array(
    '#type' => 'hidden',
    '#value' => $lang,
  );
  $form['string'] = array(
    '#theme' => 'stringoverrides_strings',
  );

  // Retrieve the words to display
  $strings = array();
  $custom_strings = array(
    FALSE => variable_get('locale_custom_disabled_strings_' . $lang, array()),
    TRUE => variable_get('locale_custom_strings_' . $lang, array()),
  );
  foreach ($custom_strings as $enabled => $replacements) {
    foreach ($replacements as $original => $replacement) {
      $strings[] = array(
        'enabled' => $enabled,
        'original' => $original,
        'replacement' => $replacement,
      );
    }
  }

  // Sort the strings and display them in the form
  usort($strings, 'stringoverrides_admin_word_sort');
  $delta = 0;
  foreach ($strings as $string) {
    $form['string'][$delta] = stringoverrides_textbox_combo($delta, $string['enabled'], $string['original'], $string['replacement']);
    $delta++;
  }
  for ($index = 0; $index < 3; $index++) {

    // Add placeholder rows
    $form['string'][$delta] = stringoverrides_textbox_combo($delta, -1);
    $delta++;
  }

  // Add the buttons to the form
  $form['more_strings'] = array(
    '#type' => 'button',
    '#value' => t('Add row'),
    '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
    '#weight' => 2,
    '#ahah' => array(
      'path' => 'admin/settings/stringoverrides/js',
      'wrapper' => 'stringoverrides-wrapper',
      'method' => 'replace',
      'effect' => 'none',
    ),
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
    '#weight' => 3,
  );
  $form['remove'] = array(
    '#type' => 'submit',
    '#value' => t('Remove disabled strings'),
    '#weight' => 4,
    '#access' => !empty($strings),
  );
  return $form;
}