Commit 3721e4d2 authored by Dries's avatar Dries

Issue #1803638 by vijaycs85, YesCT: Improve default language change process (ui and help text).

parent a686856e
......@@ -38,7 +38,7 @@ function setUp() {
parent::setUp();
// Create a new user, allow him to manage the blocks and the languages.
$this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages'));
$this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages', 'administer site configuration'));
$this->drupalLogin($this->adminUser);
// Add predefined language.
......@@ -69,9 +69,9 @@ public function testLanguageBlockVisibility() {
// Change the default language.
$edit = array(
'site_default' => 'fr',
'site_default_language' => 'fr',
);
$this->drupalpost('admin/config/regional/language', $edit, t('Save configuration'));
$this->drupalpost('admin/config/regional/settings', $edit, t('Save configuration'));
// Reset the static cache of the language list.
drupal_static_reset('language_list');
......
......@@ -22,7 +22,6 @@ function language_admin_overview_form($form, &$form_state) {
'#type' => 'table',
'#header' => array(
t('Name'),
t('Default'),
t('Weight'),
t('Operations'),
),
......@@ -36,15 +35,6 @@ function language_admin_overview_form($form, &$form_state) {
$form['languages'][$langcode]['name'] = array(
'#markup' => check_plain($language->name),
);
$form['languages'][$langcode]['default'] = array(
'#type' => 'radio',
'#parents' => array('site_default'),
'#title' => t('Set @title as default', array('@title' => $language->name)),
'#title_display' => 'invisible',
'#return_value' => $langcode,
'#default_value' => ($langcode == $default->langcode ? $langcode : NULL),
'#id' => 'edit-site-default-' . $langcode,
);
$form['languages'][$langcode]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for @title', array('@title' => $language->name)),
......@@ -87,10 +77,8 @@ function language_admin_overview_form($form, &$form_state) {
*/
function language_admin_overview_form_submit($form, &$form_state) {
$languages = language_list();
$old_default = language_default();
foreach ($languages as $langcode => $language) {
$language->default = ($form_state['values']['site_default'] == $langcode);
$language->weight = $form_state['values']['languages'][$langcode]['weight'];
language_save($language);
}
......
......@@ -24,13 +24,13 @@ function language_help($path, $arg) {
return $output;
case 'admin/config/regional/language':
return '<p>' . t('With multiple languages enabled, registered users may select their preferred language and authors can assign a specific language to content.') . '</p>';
return '<p>' . t('With multiple languages enabled, registered users may select their preferred language and authors can assign a specific language to content. The selection of what language is used to display page elements is made depending on the detection menthod settings in the <a href="@detection">Detection and Selection</a> tab.', array('@detection' => url('admin/config/regional/language/detection'))) . '</p>';
case 'admin/config/regional/language/add':
return '<p>' . t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>';
case 'admin/config/regional/language/detection':
$output = '<p>' . t("Define how to decide which language is used to display page elements (primarily text provided by Drupal and modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Define the order of evaluation of language detection methods on this page.") . '</p>';
$output = '<p>' . t('Define how to decide which language is used to display page elements (primarily text provided by Drupal and modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Define the order of evaluation of language detection methods on this page. Default language can be changed at the <a href="@region-settings">Regional settings</a> page.', array('@region-settings' => url('admin/config/regional/settings'))) . '</p>';
return $output;
case 'admin/config/regional/language/detection/session':
......@@ -877,3 +877,38 @@ function language_update_locked_weights() {
->execute();
}
}
/**
* Implements hook_form_FORM_ID_alter for system_regional_settings().
*
* @see language_system_regional_settings_form_submit()
*/
function language_form_system_regional_settings_alter(&$form, &$form_state) {
$languages = language_list();
$default = language_default();
foreach ($languages as $key => $language) {
$language_options[$key] = $language->name;
}
$form['locale']['site_default_language'] = array(
'#type' => 'select',
'#title' => t('Default language'),
'#default_value' => $default->langcode,
'#options' => $language_options,
'#description' => t('It is not recommended to change the default language on a working site. <a href="@language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', array('@language-detection' => url('admin/config/regional/language/detection'))),
'#weight' => -1,
);
// Add submit handler to save default language.
$form['#submit'][] = 'language_system_regional_settings_form_submit';
}
/**
* Form submission handler for system_regional_settings().
*
* @see language_form_system_regional_settings_alter()
*/
function language_system_regional_settings_form_submit($form, &$form_state) {
$languages = language_list();
$language = $languages[$form_state['values']['site_default_language']];
$language->default = TRUE;
language_save($language);
}
......@@ -36,7 +36,7 @@ function testLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration'));
$this->drupalLogin($admin_user);
// Check if the Default English language has no path prefix.
......@@ -59,17 +59,18 @@ function testLanguageConfiguration() {
$this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');
// Check if we can change the default language.
$this->drupalGet('admin/config/regional/language');
$this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
$this->drupalGet('admin/config/regional/settings');
$this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.');
// Change the default language.
$edit = array(
'site_default' => 'fr',
'site_default_language' => 'fr',
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
$this->assertOptionSelected('edit-site-default-language', 'fr', 'Default language updated.');
$this->assertEqual($this->getUrl(), url('admin/config/regional/settings', array('absolute' => TRUE)), 'Correct page redirection.');
// Check if a valid language prefix is added afrer changing the default
// Check if a valid language prefix is added after changing the default
// language.
$this->drupalGet('admin/config/regional/language/detection/url');
$this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
......
......@@ -37,7 +37,7 @@ function testLanguageList() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration'));
$this->drupalLogin($admin_user);
// Add predefined language.
......@@ -59,20 +59,20 @@ function testLanguageList() {
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
$this->assertRaw('"edit-site-default-' . $langcode .'"', 'Language code found.');
$this->assertRaw('"edit-languages-' . $langcode .'-weight"', 'Language code found.');
$this->assertText(t($name), 'Test language added.');
// Check if we can change the default language.
$path = 'admin/config/regional/language';
$path = 'admin/config/regional/settings';
$this->drupalGet($path);
$this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
$this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.');
// Change the default language.
$edit = array(
'site_default' => $langcode,
'site_default_language' => $langcode,
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
$this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.');
$this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.');
// Ensure we can't delete the default language.
$this->drupalGet('admin/config/regional/language/delete/' . $langcode);
......@@ -93,9 +93,9 @@ function testLanguageList() {
// Change back the default language.
$edit = array(
'site_default' => 'en',
'site_default_language' => 'en',
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->drupalPost($path, $edit, t('Save configuration'));
// Ensure 'delete' link works.
$this->drupalGet('admin/config/regional/language');
$this->clickLink(t('delete'));
......@@ -151,16 +151,16 @@ function testLanguageList() {
$this->assertText($name, 'Name found.');
// Check if we can change the default language.
$path = 'admin/config/regional/language';
$path = 'admin/config/regional/settings';
$this->drupalGet($path);
$this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
$this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.');
// Change the default language.
$edit = array(
'site_default' => $langcode,
'site_default_language' => $langcode,
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
$this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.');
$this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.');
$this->drupalPost('admin/config/regional/language/delete/en', array(), t('Delete'));
// We need raw here because %language and %langcode will add HTML.
......
......@@ -33,7 +33,7 @@ function setUp() {
parent::setUp();
// Create and login user.
$web_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
$web_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration'));
$this->drupalLogin($web_user);
// Enable French language.
......@@ -42,8 +42,10 @@ function setUp() {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
// Make French the default language.
$edit = array('site_default' => 'fr');
$this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
$edit = array(
'site_default_language' => 'fr',
);
$this->drupalpost('admin/config/regional/settings', $edit, t('Save configuration'));
// Delete English.
$this->drupalPost('admin/config/regional/language/delete/en', array(), t('Delete'));
......
......@@ -34,7 +34,7 @@ public static function getInfo() {
*/
function testMachineNameLTR() {
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'administer site configuration'));
// Log in as admin.
$this->drupalLogin($admin_user);
......@@ -48,9 +48,10 @@ function testMachineNameLTR() {
$edit['predefined_langcode'] = 'ar';
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$edit = array();
$edit['site_default'] = 'ar';
$this->drupalPost(NULL, $edit, t('Save configuration'));
$edit = array(
'site_default_language' => 'ar',
);
$this->drupalpost('admin/config/regional/settings', $edit, t('Save configuration'));
// Verify that the machine name field is still LTR for a new content type.
$this->drupalGet('admin/structure/types/add');
......
......@@ -75,7 +75,7 @@ function testStringTranslation() {
t($name, array(), array('langcode' => $langcode));
// Reset locale cache.
locale_reset();
$this->assertRaw('"edit-site-default-' . $langcode .'"', t('Language code found.'));
$this->assertRaw('"edit-languages-' . $langcode .'-weight"', t('Language code found.'));
$this->assertText(t($name), t('Test language added.'));
$this->drupalLogout();
......
......@@ -740,6 +740,11 @@ function locale_form_language_admin_overview_form_alter(&$form, &$form_state) {
'#markup' => t('not applicable'),
);
}
// #type = link doesn't work with #weight on table.
// reset and set it back after locale_statistics to get it at the right end.
$operations = $form['languages'][$langcode]['operations'];
unset($form['languages'][$langcode]['operations']);
$form['languages'][$langcode]['operations'] = $operations;
}
}
......
......@@ -30,7 +30,7 @@ public static function getInfo() {
function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields', 'administer node display', 'administer languages'));
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields', 'administer node display', 'administer languages', 'administer site configuration'));
$this->drupalLogin($web_user);
}
......@@ -59,9 +59,9 @@ function testNodeTypeInitialLanguageDefaults() {
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$edit = array(
'site_default' => 'hu',
'site_default_language' => 'hu',
);
$this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
$this->drupalpost('admin/config/regional/settings', $edit, t('Save configuration'));
// Tests the initial language after changing the site default language.
// First unhide the language selector.
......
......@@ -31,7 +31,7 @@ function setUp() {
parent::setUp();
// Create and login user.
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages'));
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration'));
$this->drupalLogin($test_user);
}
......@@ -57,12 +57,14 @@ function testLanguages() {
$this->assertFieldByXPath('//input[@name="keys"]', 'language:fr', 'Language filter added to query.');
// Change the default language and delete English.
$path = 'admin/config/regional/language';
$path = 'admin/config/regional/settings';
$this->drupalGet($path);
$this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
$edit = array('site_default' => 'fr');
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
$this->assertOptionSelected('edit-site-default-language', 'en', 'Default language updated.');
$edit = array(
'site_default_language' => 'fr',
);
$this->drupalpost($path, $edit, t('Save configuration'));
$this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.');
$this->drupalPost('admin/config/regional/language/delete/en', array(), t('Delete'));
}
}
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