Issue #2927338 by berdir, anmolgoyal74, swatichouhan012, smustgrave, alexpott, gábor hojtsy: Ensure config entity langcode property does not change when installing, adding or editing a language

(cherry picked from commit 9e7842eb89)
merge-requests/11210/head
Alex Pott 2025-02-08 19:04:31 +00:00
parent b436c8c9c4
commit 045cc0e43f
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
8 changed files with 40 additions and 10 deletions

View File

@ -1691,6 +1691,13 @@ function install_download_additional_translations_operations(&$install_state) {
if (!($language = ConfigurableLanguage::load($langcode))) {
// Create the language if not already shipped with a profile.
$language = ConfigurableLanguage::createFromLangcode($langcode);
$standard_languages = LanguageManager::getStandardLanguageList();
if (isset($standard_languages[$langcode])) {
// Use the localized language label since the site is being installed
// with that language.
$language->setName($standard_languages[$langcode][1]);
}
}
$language->save();

View File

@ -152,7 +152,11 @@ class LanguageAddForm extends LanguageFormBase {
}
else {
$standard_languages = LanguageManager::getStandardLanguageList();
$label = $standard_languages[$langcode][0];
// Translate the label to the current language, this is consistent with
// the label in the form select, see
// \Drupal\language\ConfigurableLanguageManager::getStandardLanguageListWithoutConfigured().
// phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
$label = $this->t($standard_languages[$langcode][0]);
$direction = $standard_languages[$langcode][2] ?? ConfigurableLanguage::DIRECTION_LTR;
}
$entity->set('id', $langcode);

View File

@ -52,10 +52,6 @@ abstract class LanguageFormBase extends EntityForm {
'#title' => $this->t('Language code'),
'#markup' => $language->id(),
];
$form['langcode'] = [
'#type' => 'value',
'#value' => $language->id(),
];
}
else {
$form['langcode'] = [

View File

@ -316,7 +316,9 @@ class LocaleHooks {
*/
#[Hook('form_language_admin_edit_form_alter')]
public function formLanguageAdminEditFormAlter(&$form, FormStateInterface $form_state) : void {
if ($form['langcode']['#type'] == 'value' && $form['langcode']['#value'] == 'en') {
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
$language = $form_state->getFormObject()->getEntity();
if ($language->id() == 'en') {
$form['locale_translate_english'] = [
'#title' => t('Enable interface translation to English'),
'#type' => 'checkbox',

View File

@ -120,7 +120,8 @@ class DistributionProfileTranslationQueryTest extends InstallerTestBase {
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertSession()->pageTextContains('German');
// cspell:ignore deutsch
$this->assertSession()->pageTextContains('Deutsch');
$this->assertSession()->pageTextNotContains('English');
}

View File

@ -110,7 +110,8 @@ class DistributionProfileTranslationTest extends InstallerTestBase {
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertSession()->pageTextContains('German');
// cspell:ignore deutsch
$this->assertSession()->pageTextContains('Deutsch');
$this->assertSession()->pageTextNotContains('English');
}

View File

@ -63,7 +63,8 @@ class InstallerTranslationQueryTest extends InstallerTestBase {
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertSession()->pageTextContains('German');
// cspell:ignore deutsch
$this->assertSession()->pageTextContains('Deutsch');
$this->assertSession()->pageTextNotContains('English');
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Database\Database;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\Entity\User;
/**
@ -86,7 +87,8 @@ class InstallerTranslationTest extends InstallerTestBase {
// Verify German was configured but not English.
$this->drupalGet('admin/config/regional/language');
$this->assertSession()->pageTextContains('German');
// cspell:ignore deutsch
$this->assertSession()->pageTextContains('Deutsch');
$this->assertSession()->pageTextNotContains('English');
// The current container still has the english as current language, rebuild.
@ -142,7 +144,20 @@ class InstallerTranslationTest extends InstallerTestBase {
$this->submitForm($edit, 'Add language');
$override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
$this->assertFalse($override_en->isNew());
$this->assertSession()->pageTextContains('English de');
$this->assertEquals('Anonymous', $override_en->get('anonymous'));
$english = ConfigurableLanguage::load('en');
$this->assertEquals('de', $english->language()->getId(), 'The langcode of the english language is de.');
// English is guaranteed to be the second language, click the second
// language edit link.
$this->clickLink('Edit', 1);
$this->assertSession()->fieldValueEquals('label', 'English de');
$this->submitForm([], 'Save language');
$english = ConfigurableLanguage::load('en');
$this->assertEquals('de', $english->language()->getId(), 'The langcode of the english language is de.');
}
/**
@ -165,6 +180,9 @@ msgstr "Save and continue $langcode"
msgid "Anonymous"
msgstr "Anonymous $langcode"
msgid "English"
msgstr "English $langcode"
msgid "Resolve all issues below to continue the installation. For help configuring your database server, see the <a href="https://www.drupal.org/docs/installing-drupal">installation handbook</a>, or contact your hosting provider."
msgstr "Beheben Sie alle Probleme unten, um die Installation fortzusetzen. Informationen zur Konfiguration der Datenbankserver finden Sie in der <a href="https://www.drupal.org/docs/installing-drupal">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter."