Unverified Commit 9e7842eb authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2927338 by berdir, anmolgoyal74, swatichouhan012, smustgrave, alexpott,...

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
parent 0ed3655f
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1716,6 +1716,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();

+5 −1
Original line number Diff line number Diff line
@@ -152,7 +152,11 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
    }
    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);
+0 −4
Original line number Diff line number Diff line
@@ -52,10 +52,6 @@ public function commonForm(array &$form) {
        '#title' => $this->t('Language code'),
        '#markup' => $language->id(),
      ];
      $form['langcode'] = [
        '#type' => 'value',
        '#value' => $language->id(),
      ];
    }
    else {
      $form['langcode'] = [
+3 −1
Original line number Diff line number Diff line
@@ -316,7 +316,9 @@ public function formLanguageAdminAddFormAlter(&$form, FormStateInterface $form_s
   */
  #[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',
+2 −1
Original line number Diff line number Diff line
@@ -120,7 +120,8 @@ public function testInstalled(): void {

    // 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');
  }

Loading