Skip to content
Snippets Groups Projects
Commit 95af12b5 authored by catch's avatar catch
Browse files

Issue #3005641 by ridhimaabrol24, matsbla, tanubansal, jungle, msankhala, dww,...

Issue #3005641 by ridhimaabrol24, matsbla, tanubansal, jungle, msankhala, dww, quietone, hchonov: Exception is thrown on changing "Site language" setting of a user if user account is translated
parent cd04aa14
No related branches found
No related tags found
No related merge requests found
......@@ -272,8 +272,11 @@ public function form(array $form, FormStateInterface $form_state) {
// separately, assume that the user profile data is in the user's preferred
// language. This entity builder provides that synchronization. For
// use-cases where this synchronization is not desired, a module can alter
// or remove this item.
$form['#entity_builders']['sync_user_langcode'] = '::syncUserLangcode';
// or remove this item. Sync user langcode only when a user registers and
// not when a user is updated or translated.
if ($register) {
$form['#entity_builders']['sync_user_langcode'] = '::syncUserLangcode';
}
$system_date_config = \Drupal::config('system.date');
$form['timezone'] = [
......
......@@ -174,4 +174,53 @@ public function testUserWellKnownChangePasswordAnon() {
$this->assertSession()->statusCodeEquals(403);
}
/**
* Tests that a user is able to change site language.
*/
public function testUserChangeSiteLanguage() {
// Install these modules here as these aren't needed for other test methods.
\Drupal::service('module_installer')->install([
'content_translation',
'language',
]);
// Create and login as an admin user to add a new language and enable
// translation for user accounts.
$adminUser = $this->drupalCreateUser([
'administer account settings',
'administer languages',
'administer content translation',
'administer users',
'translate any entity',
]);
$this->drupalLogin($adminUser);
// Add a new language into the system.
$edit = [
'predefined_langcode' => 'fr',
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
$this->assertSession()->pageTextContains('French');
// Enable translation for user accounts.
$edit = [
'language[content_translation]' => 1,
];
$this->drupalPostForm('admin/config/people/accounts', $edit, 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
// Create a regular user for whom translation will be enabled.
$webUser = $this->drupalCreateUser();
// Create a translation for a regular user account.
$this->drupalPostForm('user/' . $webUser->id() . '/translations/add/en/fr', [], 'Save');
$this->assertSession()->pageTextContains('The changes have been saved.');
// Update the site language of the user account.
$edit = [
'preferred_langcode' => 'fr',
];
$this->drupalPostForm('user/' . $webUser->id() . '/edit', $edit, 'Save');
$this->assertSession()->statusCodeEquals(200);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment