- Patch #1099396 by Désiré, droplet, plach: language_count() is never decremented when removing a language.

merge-requests/26/head
Dries Buytaert 2011-05-01 06:31:39 -04:00
parent 3f154706a3
commit 400284fb2c
4 changed files with 40 additions and 1 deletions

View File

@ -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;
}

View File

@ -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));

View File

@ -125,6 +125,14 @@ function locale_update_7002() {
}
}
/**
* Update "language_count" variable.
*/
function locale_update_7003() {
$languages = language_list('enabled');
variable_set('language_count', count($languages[1]));
}
/**
* @} End of "addtogroup updates-6.x-to-7.x"
*/

View File

@ -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');