summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2011-05-01 10:31:14 (GMT)
committerDries Buytaert2011-05-01 10:31:14 (GMT)
commit17d17254c13e5aadd77d142c9ddd62dcdc3fcb40 (patch)
treede5fdb1aba5485d91fd7364c409addbb6c3b933a
parent5e142ee288f0d7e69898ad54841bceeee5e4e232 (diff)
- Patch #1099396 by Désiré, droplet, plach: language_count() is never decremented when removing a language.
-rw-r--r--includes/bootstrap.inc3
-rw-r--r--modules/locale/locale.admin.inc3
-rw-r--r--modules/locale/locale.test27
3 files changed, 32 insertions, 1 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 29cb738..6322b91 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -2292,6 +2292,9 @@ function drupal_language_types() {
* Return true if there is more than one language enabled.
*/
function drupal_multilingual() {
+ // The "language_count" variable stores the number of enabled languages to
+ // avoid unnecessarily querying the database when building the list of
+ // enabled languages on monolingual sites.
return variable_get('language_count', 1) > 1;
}
diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc
index 3e4c6f1..de16133 100644
--- a/modules/locale/locale.admin.inc
+++ b/modules/locale/locale.admin.inc
@@ -467,6 +467,9 @@ function locale_languages_delete_form_submit($form, &$form_state) {
->fields(array('language' => ''))
->condition('language', $form_state['values']['langcode'])
->execute();
+ if ($languages[$form_state['values']['langcode']]->enabled) {
+ variable_set('language_count', variable_get('language_count', 1) - 1);
+ }
module_invoke_all('multilingual_settings_changed');
$variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
drupal_set_message(t('The language %locale has been removed.', $variables));
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 765bfb6..5e9e833 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -129,7 +129,7 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
$this->drupalGet('admin/config/regional/language');
$this->clickLink(t('delete'));
$this->assertText(t('Are you sure you want to delete the language'), t('"delete" link is correct.'));
- // Delete the language.
+ // Delete an enabled language.
$this->drupalGet('admin/config/regional/language/delete/' . $langcode);
// First test the 'cancel' link.
$this->clickLink(t('Cancel'));
@@ -144,6 +144,31 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
// Verify that language is no longer found.
$this->drupalGet('admin/config/regional/language/delete/' . $langcode);
$this->assertResponse(404, t('Language no longer found.'));
+ // Make sure the "language_count" variable has been updated correctly.
+ drupal_static_reset('language_list');
+ $enabled = language_list('enabled');
+ $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.'));
+ // Delete a disabled language.
+ // Disable an enabled language.
+ $edit = array(
+ 'enabled[fr]' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Save configuration'));
+ $this->assertNoFieldChecked('edit-enabled-fr', t('French language disabled.'));
+ // Get the count of enabled languages.
+ drupal_static_reset('language_list');
+ $enabled = language_list('enabled');
+ // Delete the disabled language.
+ $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete'));
+ // We need raw here because %locale will add HTML.
+ $this->assertRaw(t('The language %locale has been removed.', array('%locale' => 'French')), t('Disabled language has been removed.'));
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
+ // Verify that language is no longer found.
+ $this->drupalGet('admin/config/regional/language/delete/fr');
+ $this->assertResponse(404, t('Language no longer found.'));
+ // Make sure the "language_count" variable has not changed.
+ $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.'));
+
// Ensure we can't delete the English language.
$this->drupalGet('admin/config/regional/language/delete/en');