diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 59776aa..0cf5dcd 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -19,6 +19,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\field\Entity\FieldStorageConfig; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/core/modules/config_translation/src/ConfigEntityMapper.php b/core/modules/config_translation/src/ConfigEntityMapper.php index 5bc03cc..4a6d275 100644 --- a/core/modules/config_translation/src/ConfigEntityMapper.php +++ b/core/modules/config_translation/src/ConfigEntityMapper.php @@ -43,7 +43,7 @@ class ConfigEntityMapper extends ConfigNamesMapper { /** * Loaded entity instance to help produce the translation interface. * - * @var \Drupal\Core\Entity\EntityInterface + * @var \Drupal\Core\Config\Entity\ConfigEntityInterface */ protected $entity; diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index c7218df..18b5a21 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -13,6 +13,8 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\WebTestBase; @@ -28,7 +30,21 @@ class ConfigTranslationUiTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'contact', 'contact_test', 'config_translation', 'config_translation_test', 'views', 'views_ui', 'contextual', 'filter', 'filter_test'); + public static $modules = [ + 'config_translation', + 'config_translation_test', + 'contact', + 'contact_test', + 'contextual', + 'entity_test', + 'field_test', + 'field_ui', + 'filter', + 'filter_test', + 'node', + 'views', + 'views_ui', + ]; /** * Languages to enable. @@ -610,6 +626,46 @@ public function testViewsTranslationUI() { } /** + * Tests the translation of field and field storage configuration. + */ + public function testFieldConfigTranslation() { + // Add a test field which has a translatable field setting and a + // translatable field storage setting. + $field_name = strtolower($this->randomMachineName()); + $field_storage = FieldStorageConfig::create([ + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'type' => 'test_field', + ]); + + $translatable_storage_setting = $this->randomString(); + $field_storage->setSetting('translatable_storage_setting', $translatable_storage_setting); + $field_storage->save(); + + $bundle = strtolower($this->randomMachineName()); + entity_test_create_bundle($bundle); + $field = FieldConfig::create([ + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'bundle' => $bundle, + ]); + + $translatable_field_setting = $this->randomString(); + $field->setSetting('translatable_field_setting', $translatable_field_setting); + $field->save(); + + $this->drupalLogin($this->translatorUser); + + $this->drupalGet("/entity_test/structure/$bundle/fields/entity_test.$bundle.$field_name/translate"); + $this->clickLink('Add'); + + $this->assertText('Translatable field setting'); + $this->assertText(SafeMarkup::checkPlain($translatable_field_setting)); + $this->assertText('Translatable storage setting'); + $this->assertText(SafeMarkup::checkPlain($translatable_storage_setting)); + } + + /** * Test translation storage in locale storage. */ public function testLocaleDBStorage() { diff --git a/core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php b/core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php index 8b054bd..740b722 100644 --- a/core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php +++ b/core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php @@ -14,6 +14,8 @@ * Tests the functionality provided by the configuration field mapper. * * @group config_translation + * + * @coversDefaultClass \Drupal\config_translation\ConfigFieldMapper */ class ConfigFieldMapperTest extends UnitTestCase { @@ -38,6 +40,9 @@ class ConfigFieldMapperTest extends UnitTestCase { */ protected $entityManager; + /** + * {@inheritdoc} + */ protected function setUp() { $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); $this->entity = $this->getMock('Drupal\field\FieldConfigInterface'); @@ -70,6 +75,8 @@ protected function setUp() { /** * Tests ConfigFieldMapper::setEntity(). + * + * @covers ::setEntity */ public function testSetEntity() { $entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface'); diff --git a/core/modules/field/tests/modules/field_test/config/schema/field_test.schema.yml b/core/modules/field/tests/modules/field_test/config/schema/field_test.schema.yml index 48f5dcf..8e06db1 100644 --- a/core/modules/field/tests/modules/field_test/config/schema/field_test.schema.yml +++ b/core/modules/field/tests/modules/field_test/config/schema/field_test.schema.yml @@ -65,6 +65,9 @@ field.storage_settings.test_field: config_data_from_storage_setting: type: boolean label: 'Test FieldItemInterface::storageSettingsToConfigData()' + translatable_storage_setting: + type: label + label: 'Translatable storage setting' field.storage_settings.test_field_with_dependencies: type: field.storage_settings.test_field @@ -88,6 +91,9 @@ field.field_settings.test_field: config_data_from_field_setting: type: boolean label: 'Test FieldItemInterface::fieldSettingsToConfigData()' + translatable_field_setting: + type: label + label: 'Translatable field setting' field.field_settings.test_field_with_dependencies: type: field.field_settings.test_field diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index 9886b03..42eb11e 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -33,6 +33,7 @@ public static function defaultStorageSettings() { 'test_field_storage_setting' => 'dummy test string', 'changeable' => 'a changeable field storage setting', 'unchangeable' => 'an unchangeable field storage setting', + 'translatable_storage_setting' => 'a translatable field storage setting', ) + parent::defaultStorageSettings(); } @@ -42,6 +43,7 @@ public static function defaultStorageSettings() { public static function defaultFieldSettings() { return array( 'test_field_setting' => 'dummy test string', + 'translatable_field_setting' => 'a translatable field setting', ) + parent::defaultFieldSettings(); }