Issue #2584603 by tstoeckler, claudiu.cristea, alexpott, nicrodgers, Gábor Hojtsy, dawehner, kattekrab, idflood, C_Logemann: PHP exception on manage fields after enabling Configuration Translation
parent
71cd91736f
commit
766c15423f
|
@ -174,6 +174,9 @@ interface ConfigMapperInterface {
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,10 @@ class NodeTypeMapper extends ConfigEntityMapper {
|
|||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 @@ class NodeTypeTranslationTest extends WebTestBase {
|
|||
$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 @@ class NodeTypeTranslationTest extends WebTestBase {
|
|||
$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 @@ class NodeTypeTranslationTest extends WebTestBase {
|
|||
$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'));
|
||||
|
|
Loading…
Reference in New Issue