function stringoverrides_admin in String Overrides 7
Same name and namespace in other branches
- 5 stringoverrides.admin.inc \stringoverrides_admin()
- 6 stringoverrides.admin.inc \stringoverrides_admin()
Menu callback for the String Overrides module to display its administration
1 string reference to 'stringoverrides_admin'
- stringoverrides_menu in ./
stringoverrides.module - Implements hook_menu().
File
- ./
stringoverrides.admin.inc, line 11 - Admin page callbacks for the String Overrides module.
Code
function stringoverrides_admin($form, $form_state, $lang = NULL) {
// See which language we're modifying
if (empty($lang)) {
$language = language_default();
$lang = $language->language;
}
// Setup the form
$form['#cache'] = TRUE;
$form['#attached']['css'][drupal_get_path('module', 'stringoverrides') . '/stringoverrides.admin.css'] = array();
$form['lang'] = array(
'#type' => 'hidden',
'#value' => $lang,
);
$form['string'] = array(
'#tree' => TRUE,
'#theme' => 'stringoverrides_strings',
);
// Retrieve the string overrides from the variables table.
$words = array(
FALSE => variable_get("locale_custom_disabled_strings_{$lang}", array()),
TRUE => variable_get("locale_custom_strings_{$lang}", array()),
);
$strings = array();
foreach ($words as $enabled => $custom_strings) {
foreach ($custom_strings as $context => $translations) {
foreach ($translations as $source => $translation) {
$strings[] = array(
'enabled' => $enabled,
'context' => $context,
'source' => $source,
'translation' => $translation,
);
}
}
}
// See how many string rows there should be.
$string_count = 0;
if (isset($form_state['string_count'])) {
$string_count = $form_state['string_count'];
}
else {
$string_count = count($strings) + 1;
}
// Sort the strings and display them in the form.
usort($strings, 'stringoverrides_admin_word_sort');
for ($index = 0; $index < $string_count; $index++) {
if (isset($strings[$index])) {
$string = $strings[$index];
$form['string'][$index] = stringoverrides_textbox_combo($index, $string['enabled'], $string['context'], $string['source'], $string['translation']);
}
else {
$form['string'][$index] = stringoverrides_textbox_combo($index, -1);
}
}
// Add the buttons to the form.
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
'container-inline',
),
),
);
$form['actions']['more_strings'] = array(
'#type' => 'submit',
'#value' => t('Add row'),
'#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
'#weight' => 2,
'#submit' => array(
'stringoverrides_more_strings_submit',
),
'#ajax' => array(
'callback' => 'stringoverrides_ajax',
'wrapper' => 'stringoverrides-wrapper',
'method' => 'replace',
'effect' => 'none',
),
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#weight' => 3,
);
$form['actions']['remove'] = array(
'#type' => 'submit',
'#value' => t('Remove disabled strings'),
'#weight' => 4,
'#access' => !empty($strings),
);
return $form;
}