Commit 4c19bdca authored by Dries's avatar Dries

Issue #1869328 by vijaycs85, Gábor Hojtsy, manningpete, YesCT: Restore simplicity of language list.

parent 32e23b57
......@@ -13,7 +13,7 @@
*/
function language_admin_overview_form($form, &$form_state) {
drupal_static_reset('language_list');
$languages = language_list(LANGUAGE_ALL);
$languages = language_list();
$default = language_default();
$form['languages'] = array(
......@@ -33,22 +33,8 @@ function language_admin_overview_form($form, &$form_state) {
foreach ($languages as $langcode => $language) {
$form['languages'][$langcode]['#attributes']['class'][] = 'draggable';
$form['languages'][$langcode]['#weight'] = $language->weight;
$title = check_plain($language->name);
$description = '';
switch ($langcode) {
case LANGUAGE_NOT_APPLICABLE:
$description = t('For language independent content.');
break;
case LANGUAGE_NOT_SPECIFIED:
$description = t('Use this when the language is not (yet) known.');
break;
}
if (!empty($description)) {
$title .= '<div class="description">' . $description . '</div>';
}
$form['languages'][$langcode]['name'] = array(
'#markup' => $title,
'#markup' => check_plain($language->name),
);
$form['languages'][$langcode]['default'] = array(
'#type' => 'radio',
......@@ -70,20 +56,15 @@ function language_admin_overview_form($form, &$form_state) {
'#delta' => 30,
);
$links = array();
if (empty($language->locked)) {
$links['edit'] = array(
'title' => t('edit'),
'href' => 'admin/config/regional/language/edit/' . $langcode,
$links['edit'] = array(
'title' => t('edit'),
'href' => 'admin/config/regional/language/edit/' . $langcode,
);
if ($langcode != $default->langcode) {
$links['delete'] = array(
'title' => t('delete'),
'href' => 'admin/config/regional/language/delete/' . $langcode,
);
if ($langcode != $default->langcode) {
$links['delete'] = array(
'title' => t('delete'),
'href' => 'admin/config/regional/language/delete/' . $langcode,
);
}
}
else {
$form['languages'][$langcode]['default']['#attributes']['disabled'] = 'disabled';
}
$form['languages'][$langcode]['operations'] = array(
'#type' => 'operations',
......@@ -105,7 +86,7 @@ function language_admin_overview_form($form, &$form_state) {
* Process language overview form submissions, updating existing languages.
*/
function language_admin_overview_form_submit($form, &$form_state) {
$languages = language_list(LANGUAGE_ALL);
$languages = language_list();
$old_default = language_default();
foreach ($languages as $langcode => $language) {
......
......@@ -513,6 +513,9 @@ function language_save($language) {
// Update language count based on unlocked language count.
language_update_count();
// Update weight of locked system languages.
language_update_locked_weights();
// Kill the static cache in language_list().
drupal_static_reset('language_list');
......@@ -559,6 +562,9 @@ function language_delete($langcode) {
language_update_count();
// Update weight of locked system languages.
language_update_locked_weights();
drupal_static_reset('language_list');
$t_args = array('%language' => $language->name, '%langcode' => $language->langcode);
......@@ -854,3 +860,20 @@ function language_set_browser_drupal_langcode_mappings($mappings) {
$config->setData($mappings);
$config->save();
}
/**
* Updates locked system language weights.
*/
function language_update_locked_weights() {
// Get maximum weight to update the system languages to keep them on bottom.
$max_weight = db_query('SELECT MAX(weight) FROM {language} WHERE locked = 0')->fetchField();
// Loop locked languages to maintain the existing order.
foreach (language_list(LANGUAGE_LOCKED) as $language) {
$max_weight++;
// Update system languages weight.
db_update('language')
->fields(array('weight' => $max_weight))
->condition('langcode', $language->langcode)
->execute();
}
}
......@@ -99,4 +99,65 @@ function testLanguageConfiguration() {
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
}
/**
* Functional tests for setting system language weight on adding, editing and deleting languages.
*/
function testLanguageConfigurationWeight() {
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
$this->drupalLogin($admin_user);
$this->checkConfigurableLanguageWeight();
// Add predefined language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this->drupalPost('admin/config/regional/language/add', $edit, 'Add language');
$this->checkConfigurableLanguageWeight('after adding new language');
// Re-ordering languages.
$edit = array(
'languages[en][weight]' => $this->getHighestConfigurableLanguageWeight() + 1,
);
$this->drupalPost('admin/config/regional/language', $edit, 'Save configuration');
$this->checkConfigurableLanguageWeight('after re-ordering');
// Remove predefined language.
$edit = array(
'confirm' => 1,
);
$this->drupalPost('admin/config/regional/language/delete/fr', $edit, 'Delete');
$this->checkConfigurableLanguageWeight('after deleting a language');
}
/**
* Validates system languages are ordered after configurable languages.
*
* @param string $state
* (optional) A string for customizing assert messages, containing the
* description of the state of the check, for example: 'after re-ordering'.
* Defaults to 'by default'.
*/
protected function checkConfigurableLanguageWeight($state = 'by default') {
// Reset language list.
drupal_static_reset('language_list');
$max_configurable_language_weight = $this->getHighestConfigurableLanguageWeight();
$replacements = array('@event' => $state);
foreach (language_list(LANGUAGE_LOCKED) as $locked_language) {
$replacements['%language'] = $locked_language->name;
$this->assertTrue($locked_language->weight > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements));
}
}
/**
* Helper to get maximum weight of configurable (unlocked) languages.
*
* @return int
* Maximum weight of configurable languages.
*/
protected function getHighestConfigurableLanguageWeight(){
return db_query('SELECT MAX(weight) FROM {language} WHERE locked = 0')->fetchField();
}
}
......@@ -22,7 +22,7 @@ function translation_entity_help($path, $arg) {
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Enabling translation') . '</dt>';
$output .= '<dd><p>' . t('Before you can translate content, there must be at least two non-system languages added on the <a href="!url">languages administration</a> page.', array('!url' => url('admin/config/regional/language'))) . '</p>';
$output .= '<dd><p>' . t('Before you can translate content, there must be at least two languages added on the <a href="!url">languages administration</a> page.', array('!url' => url('admin/config/regional/language'))) . '</p>';
$output .= '<p>' . t('After adding languages, <a href="!url">configure translation</a>.', array('!url' => url('admin/config/regional/content-language'))) . '</p>';
$output .= '<dt>' . t('Translating content') . '</dt>';
$output .= '<dd>' . t('After enabling translation you can create a new piece of content, or edit existing content and assign it a language. Then, you will see a <em>Translations</em> tab or link that will gives an overview of the translation status for the current content. From there, you can add translations and edit or delete existing translations. This process is similar for every translatable element on your site, such as taxonomy terms, comments or user accounts.') . '</dd>';
......@@ -38,7 +38,7 @@ function translation_entity_help($path, $arg) {
case 'admin/config/regional/content-language':
$output = '';
if (!language_multilingual()) {
$output .= '<br/>' . t('Before you can translate content, there must be at least two non-system languages added on the <a href="!url">languages administration</a> page.', array('!url' => url('admin/config/regional/language')));
$output .= '<br/>' . t('Before you can translate content, there must be at least two languages added on the <a href="!url">languages administration</a> page.', array('!url' => url('admin/config/regional/language')));
}
return $output;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment