diff --git a/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php b/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php index 89c5914..3f3e9a7 100644 --- a/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php +++ b/core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php @@ -18,7 +18,9 @@ * Converts entity route arguments to unmodified entities as opposed to * converting to entities with overrides, such as the negotiated language. * - * This converter applies only if the path is an admin path. + * This converter applies only if the path is an admin path, the entity is + * a config entity, and the "use_current_language" element is not set to TRUE + * on the parameter definition. * * Due to this converter having a higher weight than the default * EntityConverter, every time this applies, it takes over the conversion duty @@ -88,6 +90,10 @@ public function convert($value, $definition, $name, array $defaults) { * {@inheritdoc} */ public function applies($definition, $name, Route $route) { + if (isset($definition['use_current_language']) && $definition['use_current_language']) { + return FALSE; + } + if (parent::applies($definition, $name, $route)) { $entity_type_id = substr($definition['type'], strlen('entity:')); // If the entity type is dynamic, defer checking to self::convert(). diff --git a/core/modules/config/tests/config_test/config_test.routing.yml b/core/modules/config/tests/config_test/config_test.routing.yml index 3a96481..40b5f7c 100644 --- a/core/modules/config/tests/config_test/config_test.routing.yml +++ b/core/modules/config/tests/config_test/config_test.routing.yml @@ -21,6 +21,20 @@ entity.config_test.edit_form: requirements: _access: 'TRUE' +config_test.entity_using_current_language: + path: '/admin/structure/config_test/entity_using_current_language/{config_test}' + defaults: + _entity_form: 'config_test' + _title_callback: '\Drupal\config_test\ConfigTestController::editTitle' + requirements: + _access: 'TRUE' + options: + parameters: + config_test: + type: entity:config_test + # Force load in current interface language. + use_current_language: 'TRUE' + entity.config_test.edit_form_config_test_no_status: path: '/admin/structure/config_test/manage/{config_test_no_status}' defaults: diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php index 2864317..3adb432 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -120,4 +120,40 @@ public function testHiddenEntities() { $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_year/translate'); } + /** + * Tests the translated version of a config entity shows when wanted. + */ + public function testConfigUsingCurrentLanguage() { + $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration')); + $this->drupalLogin($admin_user); + $langcode = 'fr'; + $edit = array( + 'predefined_langcode' => $langcode, + ); + // Add a language and set it as the default + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $this->assertText('French', 'Language added successfully.'); + $this->drupalGet('admin/config/regional/settings'); + $edit = array( + 'site_default_language' => $langcode, + ); + $this->drupalPostForm(NULL, $edit, t('Save configuration')); + $this->rebuildContainer(); + + $entity_label = 'A label to translate'; + $es_entity_label = 'Une étiquette pour traduire'; + $test_entity = entity_create('config_test', array( + 'id' => $this->randomMachineName(), + 'label' => $entity_label, + )); + $test_entity->save(); + + \Drupal::languageManager() + ->getLanguageConfigOverride($langcode, 'config_test.' . $test_entity->id()) + ->set('label', $es_entity_label) + ->save(); + + $this->drupalGet('admin/structure/config_test/entity_using_current_language/' . $test_entity->id()); + $this->assertText($es_entity_label); + } }