diff --git a/core/modules/config_translation/src/ConfigMapperInterface.php b/core/modules/config_translation/src/ConfigMapperInterface.php index b56e401..507b191 100644 --- a/core/modules/config_translation/src/ConfigMapperInterface.php +++ b/core/modules/config_translation/src/ConfigMapperInterface.php @@ -174,6 +174,9 @@ public function getConfigNames(); /** * Adds the given configuration name to the list of names. * + * Note that it is the responsibility of the calling code to ensure that the + * configuration exists. + * * @param string $name * Configuration name. */ diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php new file mode 100644 index 0000000..1735fc7 --- /dev/null +++ b/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php @@ -0,0 +1,79 @@ +siteDirectory . '/files/translations', 0777, TRUE); + file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.eo.po', $this->getPo('eo')); + + parent::setUpLanguage(); + + $this->translations['Save and continue'] = 'Save and continue eo'; + } + + /** + * Returns the string for the test .po file. + * + * @param string $langcode + * The language code. + * @return string + * Contents for the test .po file. + */ + protected function getPo($langcode) { + return <<drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'en'], t('Add custom language')); + $this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'fr'], t('Add custom language')); + + $edit = [ + 'modules[Multilingual][config_translation][enable]' => TRUE, + ]; + $this->drupalPostForm('admin/modules', $edit, t('Install')); + + $this->drupalGet('/admin/structure/types/manage/article/fields'); + $this->assertResponse(200); + } + +} diff --git a/core/modules/node/src/ConfigTranslation/NodeTypeMapper.php b/core/modules/node/src/ConfigTranslation/NodeTypeMapper.php index be0cdb8..d11364a 100644 --- a/core/modules/node/src/ConfigTranslation/NodeTypeMapper.php +++ b/core/modules/node/src/ConfigTranslation/NodeTypeMapper.php @@ -23,7 +23,10 @@ public function setEntity(ConfigEntityInterface $entity) { // Adds the title label to the translation form. $node_type = $entity->id(); - $this->addConfigName("core.base_field_override.node.$node_type.title"); + $config = $this->configFactory->get("core.base_field_override.node.$node_type.title"); + if (!$config->isNew()) { + $this->addConfigName($config->getName()); + } } } diff --git a/core/modules/node/src/Tests/NodeTypeTranslationTest.php b/core/modules/node/src/Tests/NodeTypeTranslationTest.php index 99c1558..10c6865 100644 --- a/core/modules/node/src/Tests/NodeTypeTranslationTest.php +++ b/core/modules/node/src/Tests/NodeTypeTranslationTest.php @@ -29,11 +29,18 @@ class NodeTypeTranslationTest extends WebTestBase { ); /** + * The default language code to use in this test. + * + * @var array + */ + protected $defaultLangcode = 'fr'; + + /** * Languages to enable. * * @var array */ - protected $langcodes = array('fr'); + protected $additionalLangcodes = ['es']; /** * Administrator user for tests. @@ -56,12 +63,27 @@ protected function setUp() { $this->adminUser = $this->drupalCreateUser($admin_permissions); // Add languages. - foreach ($this->langcodes as $langcode) { + foreach ($this->additionalLangcodes as $langcode) { ConfigurableLanguage::createFromLangcode($langcode)->save(); } } /** + * {@inheritdoc} + * + * Install Drupal in a language other than English for this test. This is not + * needed to test the node type translation itself but acts as a regression + * test. + * + * @see https://www.drupal.org/node/2584603 + */ + protected function installParameters() { + $parameters = parent::installParameters(); + $parameters['parameters']['langcode'] = $this->defaultLangcode; + return $parameters; + } + + /** * Tests the node type translation. */ public function testNodeTypeTranslation() { @@ -71,14 +93,13 @@ public function testNodeTypeTranslation() { $this->drupalCreateContentType(array('type' => $type, 'name' => $name)); // Translate the node type name. - $langcode = $this->langcodes[0]; + $langcode = $this->additionalLangcodes[0]; $translated_name = $langcode . '-' . $name; $edit = array( "translation[config_names][node.type.$type][name]" => $translated_name, ); // Edit the title label to avoid having an exception when we save the translation. - $this->drupalPostForm("admin/structure/types/manage/$type", array('title_label' => 'Edited title'), t('Save content type')); $this->drupalPostForm("admin/structure/types/manage/$type/translate/$langcode/add", $edit, t('Save translation')); // Check the name is translated without admin theme for editing. @@ -100,7 +121,7 @@ public function testNodeTypeTitleLabelTranslation() { $name = $this->randomString(); $this->drupalLogin($this->adminUser); $this->drupalCreateContentType(array('type' => $type, 'name' => $name)); - $langcode = $this->langcodes[0]; + $langcode = $this->additionalLangcodes[0]; // Edit the title label for it to be displayed on the translation form. $this->drupalPostForm("admin/structure/types/manage/$type", array('title_label' => 'Edited title'), t('Save content type'));