From 766c15423fa4be8ca509bbe966592ee0e48d803d Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Mon, 19 Oct 2015 17:34:46 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#2584603=20by=20tstoeckler,=20claudiu.c?= =?UTF-8?q?ristea,=20alexpott,=20nicrodgers,=20G=C3=A1bor=20Hojtsy,=20dawe?= =?UTF-8?q?hner,=20kattekrab,=20idflood,=20C=5FLogemann:=20PHP=20exception?= =?UTF-8?q?=20on=20manage=20fields=20after=20enabling=20Configuration=20Tr?= =?UTF-8?q?anslation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ConfigMapperInterface.php | 3 + .../Tests/ConfigTranslationInstallTest.php | 79 +++++++++++++++++++ .../src/ConfigTranslation/NodeTypeMapper.php | 5 +- .../src/Tests/NodeTypeTranslationTest.php | 31 ++++++-- 4 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php diff --git a/core/modules/config_translation/src/ConfigMapperInterface.php b/core/modules/config_translation/src/ConfigMapperInterface.php index b56e4016a569..507b191b4194 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 000000000000..1735fc72e850 --- /dev/null +++ b/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php @@ -0,0 +1,79 @@ +<?php + +/** + * @file + * Contains \Drupal\config_translation\Tests\ConfigTranslationInstallTest. + */ + +namespace Drupal\config_translation\Tests; + +use Drupal\simpletest\InstallerTestBase; + +/** + * Installs the config translation module on a site installed in non english. + * + * @group config_translation + */ +class ConfigTranslationInstallTest extends InstallerTestBase { + + /** + * {@inheritdoc} + */ + protected $langcode = 'eo'; + + /** + * {@inheritdoc} + */ + protected $profile = 'standard'; + + /** + * {@inheritdoc} + */ + protected function setUpLanguage() { + // Place custom local translations in the translations directory. + mkdir(DRUPAL_ROOT . '/' . $this->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 <<<ENDPO +msgid "" +msgstr "" + +msgid "Save and continue" +msgstr "Save and continue $langcode" + +msgid "Anonymous" +msgstr "Anonymous $langcode" + +msgid "Language" +msgstr "Language $langcode" +ENDPO; + } + + public function testConfigTranslation() { + $this->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 be0cdb866db9..d11364a03d08 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 99c15581a5ee..10c6865846e5 100644 --- a/core/modules/node/src/Tests/NodeTypeTranslationTest.php +++ b/core/modules/node/src/Tests/NodeTypeTranslationTest.php @@ -28,12 +28,19 @@ class NodeTypeTranslationTest extends WebTestBase { 'node', ); + /** + * 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,11 +63,26 @@ 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. */ @@ -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')); -- GitLab