diff --git a/core/lib/Drupal/Core/Field/BundleFieldDefinition.php b/core/lib/Drupal/Core/Field/BundleFieldDefinition.php index ec956d589b..c2cafaca04 100644 --- a/core/lib/Drupal/Core/Field/BundleFieldDefinition.php +++ b/core/lib/Drupal/Core/Field/BundleFieldDefinition.php @@ -235,7 +235,7 @@ public function setTranslatable($translatable) { * {@inheritdoc} */ public function isTranslatable() { - return !empty($this->definition['translatable']); + return !empty($this->definition['translatable']) && $this->getFieldStorageDefinition()->isTranslatable(); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/BundleFieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/BundleFieldDefinitionTest.php index 1ce4711664..e6b7cefe4a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/BundleFieldDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/BundleFieldDefinitionTest.php @@ -39,6 +39,13 @@ class BundleFieldDefinitionTest extends UnitTestCase { */ protected $storageDefinition; + /** + * A flag for setting if the field storage supports translation. + * + * @var bool + */ + protected $storageSupportsTranslation = TRUE; + /** * {@inheritdoc} */ @@ -63,6 +70,10 @@ protected function setUp() { $storage_definition->getMainPropertyName()->willReturn('value'); $storage_definition->getType()->willReturn($this->fieldType); $storage_definition->getName()->willReturn('Test field name'); + $storage_supports_translation = &$this->storageSupportsTranslation; + $storage_definition->isTranslatable()->will(function() use (&$storage_supports_translation) { + return $storage_supports_translation; + }); $storage_definition->getSettings()->willReturn($this->fieldTypeDefinition['storage_settings']); $storage_definition->getSetting('some_storage_setting')->willReturn($this->fieldTypeDefinition['storage_settings']['some_storage_setting']); @@ -215,6 +226,11 @@ public function testFieldTranslatable($factory_name) { $this->assertTrue($definition->isTranslatable()); $definition->setTranslatable(FALSE); $this->assertFalse($definition->isTranslatable()); + + $this->storageSupportsTranslation = FALSE; + $definition->setTranslatable(TRUE); + $this->assertFalse($this->storageDefinition->isTranslatable()); + $this->assertFalse($definition->isTranslatable()); } /**