diff --git a/core/modules/block/src/Tests/BlockLanguageTest.php b/core/modules/block/src/Tests/BlockLanguageTest.php index df5e693..d8e9f18 100644 --- a/core/modules/block/src/Tests/BlockLanguageTest.php +++ b/core/modules/block/src/Tests/BlockLanguageTest.php @@ -34,7 +34,7 @@ protected 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', 'administer site configuration')); + $this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages')); $this->drupalLogin($this->adminUser); // Add predefined language. @@ -68,7 +68,7 @@ public function testLanguageBlockVisibility() { $edit = array( 'site_default_language' => 'fr', ); - $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration')); + $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); // Check that a page has a block. $this->drupalGet('en'); diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 2224ba4..8671c3c 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -668,8 +668,8 @@ public function testSingleLanguageUI() { $edit = array( 'site_default_language' => 'ta', ); - $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration')); - $this->assertRaw(t('The configuration options have been saved.')); + $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); + $this->assertRaw(t('Configuration saved.')); // Delete English language $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete')); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 01f3d0b..d5c238b 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -55,13 +55,15 @@ function language_help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.configurable_language.collection': - return '

' . t('Reorder the added languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact detection and selection.', array('@detection' => \Drupal::url('language.negotiation'))) . '

'; + $output = '

' . t('Reorder the added languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact detection and selection.', array('@detection' => \Drupal::url('language.negotiation'))) . '

'; + $output .= '

' . t('The site default language can also be set. It is not recommended to change the default language on a working site. Configure the Selected language setting on the detection and selection page to change the fallback language for language selection.', array('@language-detection' => \Drupal::url('language.negotiation'))) . '

'; + return $output; case 'language.add': return '

' . t('Add a language to be supported by your site. If your desired language is not available, pick Custom language... at the end and provide a language code and other details manually.') . '

'; case 'language.negotiation': - $output = '

' . t('Define how to decide which language is used to display page elements (primarily text provided by 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. Be aware that some language negotiation methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed at the Regional settings page.', array('!region-settings' => \Drupal::url('system.regional_settings'))) . '

'; + $output = '

' . t('Define how to decide which language is used to display page elements (primarily text provided by 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. Be aware that some language negotiation methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the list of languages.', array('!admin-change-language' => \Drupal::url('entity.configurable_language.collection'))) . '

'; return $output; case 'language.negotiation_session': @@ -449,29 +451,6 @@ function language_get_browser_drupal_langcode_mappings() { } /** - * 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, FormStateInterface $form_state) { - $languages = \Drupal::languageManager()->getLanguages(); - $default = \Drupal::languageManager()->getDefaultLanguage(); - foreach ($languages as $key => $language) { - $language_options[$key] = $language->getName(); - } - $form['locale']['site_default_language'] = array( - '#type' => 'select', - '#title' => t('Default language'), - '#default_value' => $default->getId(), - '#options' => $language_options, - '#description' => t('It is not recommended to change the default language on a working site. Configure the Selected language setting on the detection and selection page to change the fallback language for language selection.', array('@language-detection' => \Drupal::url('language.negotiation'))), - '#weight' => -1, - ); - // Add submit handler to save default language. - $form['#submit'][] = 'language_system_regional_settings_form_submit'; -} - -/** * Implements hook_form_alter(). */ function language_form_alter(&$form, FormStateInterface $form_state) { @@ -491,15 +470,6 @@ function language_form_alter(&$form, FormStateInterface $form_state) { } /** - * Form submission handler for system_regional_settings(). - * - * @see language_form_system_regional_settings_alter() - */ -function language_system_regional_settings_form_submit($form, FormStateInterface $form_state) { - \Drupal::configFactory()->getEditable('system.site')->set('langcode', $form_state->getValue('site_default_language'))->save(); -} - -/** * Implements hook_field_info_alter(). */ function language_field_info_alter(&$info) { diff --git a/core/modules/language/src/LanguageListBuilder.php b/core/modules/language/src/LanguageListBuilder.php index e392e75..6fb2431 100644 --- a/core/modules/language/src/LanguageListBuilder.php +++ b/core/modules/language/src/LanguageListBuilder.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -98,8 +99,11 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Name'); - return $header + parent::buildHeader(); + $header = array( + 'label' => t('Name'), + 'default' => t('Default'), + ) + parent::buildHeader(); + return $header; } /** @@ -107,6 +111,14 @@ public function buildHeader() { */ public function buildRow(EntityInterface $entity) { $row['label'] = $this->getLabel($entity); + $row['default'] = array( + '#type' => 'radio', + '#parents' => array('site_default_language'), + '#title' => t('Set @title as default', array('@title' => $entity->label())), + '#title_display' => 'invisible', + '#return_value' => $entity->id(), + '#id' => 'edit-site-default-language-' . $entity->id(), + ); return $row + parent::buildRow($entity); } @@ -115,6 +127,15 @@ public function buildRow(EntityInterface $entity) { */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); + + // Mark the right language as default in the form. + $default = \Drupal::languageManager()->getDefaultLanguage(); + foreach (Element::children($form[$this->entitiesKey]) as $key) { + if ($key == $default->getId()) { + $form[$this->entitiesKey][$key]['default']['#default_value'] = $default->getId(); + } + } + $form[$this->entitiesKey]['#languages'] = $this->entities; $form['actions']['submit']['#value'] = t('Save configuration'); return $form; @@ -126,12 +147,22 @@ public function buildForm(array $form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); + // Save the default language. + foreach ($form_state->getValue($this->entitiesKey) as $id => $value) { + if (isset($this->entities[$id]) && ($id == $form_state->getValue('site_default_language'))) { + \Drupal::configFactory()->getEditable('system.site')->set('langcode', $form_state->getValue('site_default_language'))->save(); + } + } + $this->languageManager->reset(); if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) { $this->languageManager->updateLockedLanguageWeights(); } drupal_set_message(t('Configuration saved.')); + // Force the redirection to the page with the language we have just + // selected as default. + $form_state->setRedirect('entity.configurable_language.collection', array(), array('language' => $this->entities[$form_state->getValue('site_default_language')])); } } diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index 9a43437..a5efb2f 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -30,7 +30,7 @@ class LanguageConfigurationTest extends WebTestBase { function testLanguageConfiguration() { // User to add and remove language. - $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration')); + $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); $this->drupalLogin($admin_user); // Check if the Default English language has no path prefix. @@ -56,8 +56,8 @@ 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/settings'); - $this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.'); + $this->drupalGet('admin/config/regional/language'); + $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.'); // Change the default language. $edit = array( @@ -65,8 +65,8 @@ function testLanguageConfiguration() { ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->rebuildContainer(); - $this->assertOptionSelected('edit-site-default-language', 'fr', 'Default language updated.'); - $this->assertUrl(\Drupal::url('system.regional_settings', [], ['absolute' => TRUE, 'langcode' => 'fr']), [], 'Correct page redirection.'); + $this->assertFieldChecked('edit-site-default-language-fr', 'Default language updated.'); + $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'langcode' => 'fr']), [], 'Correct page redirection.'); // Check if a valid language prefix is added after changing the default // language. diff --git a/core/modules/language/src/Tests/LanguageListTest.php b/core/modules/language/src/Tests/LanguageListTest.php index 52f6e4c..e7dec66 100644 --- a/core/modules/language/src/Tests/LanguageListTest.php +++ b/core/modules/language/src/Tests/LanguageListTest.php @@ -32,7 +32,7 @@ class LanguageListTest extends WebTestBase { function testLanguageList() { // User to add and remove language. - $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration')); + $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); $this->drupalLogin($admin_user); // Add predefined language. @@ -61,17 +61,17 @@ function testLanguageList() { $english = \Drupal::service('language_manager')->getLanguage('en'); // Check if we can change the default language. - $path = 'admin/config/regional/settings'; + $path = 'admin/config/regional/language'; $this->drupalGet($path); - $this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.'); + $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.'); // Change the default language. $edit = array( 'site_default_language' => $langcode, ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->rebuildContainer(); - $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - $this->assertUrl(\Drupal::url('system.regional_settings', [], ['absolute' => TRUE, 'language' => $language])); + $this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.'); + $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); // Ensure we can't delete the default language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); @@ -146,17 +146,17 @@ function testLanguageList() { $this->assertText($name, 'Name found.'); // Check if we can change the default language. - $path = 'admin/config/regional/settings'; + $path = 'admin/config/regional/language'; $this->drupalGet($path); - $this->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.'); + $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.'); // Change the default language. $edit = array( 'site_default_language' => $langcode, ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->rebuildContainer(); - $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - $this->assertUrl(\Drupal::url('system.regional_settings', [], ['absolute' => TRUE, 'language' => $language])); + $this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.'); + $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. diff --git a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php index c574f91..d3aa814 100644 --- a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php +++ b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php @@ -39,7 +39,7 @@ protected function setUp() { $edit = array( 'site_default_language' => 'fr', ); - $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration')); + $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); // Delete English. $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete')); diff --git a/core/modules/locale/src/Tests/LocaleContentTest.php b/core/modules/locale/src/Tests/LocaleContentTest.php index 2b66904..93a5e77 100644 --- a/core/modules/locale/src/Tests/LocaleContentTest.php +++ b/core/modules/locale/src/Tests/LocaleContentTest.php @@ -47,7 +47,7 @@ public function testMachineNameLTR() { $edit = array( 'site_default_language' => 'ar', ); - $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration')); + $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); // Verify that the machine name field is still LTR for a new content type. $this->drupalGet('admin/structure/types/add'); diff --git a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php index 06793b4..bca545f 100644 --- a/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php +++ b/core/modules/node/src/Tests/NodeTypeInitialLanguageTest.php @@ -26,7 +26,7 @@ class NodeTypeInitialLanguageTest extends NodeTestBase { protected function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer languages', 'administer site configuration')); + $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer languages')); $this->drupalLogin($web_user); } @@ -57,7 +57,7 @@ function testNodeTypeInitialLanguageDefaults() { $edit = array( 'site_default_language' => 'hu', ); - $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration')); + $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); // Tests the initial language after changing the site default language. // First unhide the language selector. diff --git a/core/modules/search/src/Tests/SearchLanguageTest.php b/core/modules/search/src/Tests/SearchLanguageTest.php index 6376dd0..b6f8d2b 100644 --- a/core/modules/search/src/Tests/SearchLanguageTest.php +++ b/core/modules/search/src/Tests/SearchLanguageTest.php @@ -128,14 +128,14 @@ function testLanguages() { $this->assertNoLink('Third node en', 'Search results does not contain third English node'); // Change the default language and delete English. - $path = 'admin/config/regional/settings'; + $path = 'admin/config/regional/language'; $this->drupalGet($path); - $this->assertOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); + $this->assertFieldChecked('edit-site-default-language-en', 'Default language updated.'); $edit = array( 'site_default_language' => 'fr', ); $this->drupalPostForm($path, $edit, t('Save configuration')); - $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); + $this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.'); $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete')); } }