diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index b7bd079dcc345d67c754af2cc0dd212521cc1180..9ce46580ce9313ab014d8092874b8f90d338221d 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -430,6 +430,11 @@ function content_translation_form_field_config_edit_form_alter(array &$form, For */ function content_translation_entity_presave(EntityInterface $entity) { if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && !$entity->isNew()) { + /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */ + $manager = \Drupal::service('content_translation.manager'); + if (!$manager->isEnabled($entity->getEntityTypeId(), $entity->bundle())) { + return; + } // If we are creating a new translation we need to use the source language // as original language, since source values are the only ones available to // compare against. @@ -438,8 +443,6 @@ function content_translation_entity_presave(EntityInterface $entity) { ->getStorage($entity->entityType())->loadUnchanged($entity->id()); } $langcode = $entity->language()->getId(); - /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */ - $manager = \Drupal::service('content_translation.manager'); $source_langcode = !$entity->original->hasTranslation($langcode) ? $manager->getTranslationMetadata($entity)->getSource() : NULL; \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $langcode, $source_langcode); } diff --git a/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module b/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module index 1275a278bc9cedf8fb94854c58407bf221bb2326..d1f321b59c604eebfdd6d1425bd3f0f6e7d620bf 100644 --- a/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module +++ b/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module @@ -13,7 +13,14 @@ function content_translation_test_entity_bundle_info_alter(&$bundles) { // Store the initial status of the "translatable" property for the // "entity_test_mul" bundle. - \Drupal::state()->set('content_translation_test.translatable', !empty($bundles['entity_test_mul']['entity_test_mul']['translatable'])); + $translatable = !empty($bundles['entity_test_mul']['entity_test_mul']['translatable']); + \Drupal::state()->set('content_translation_test.translatable', $translatable); + // Make it translatable if Content Translation did not. This will make the + // entity object translatable even if it is disabled in Content Translation + // settings. + if (!$translatable) { + $bundles['entity_test_mul']['entity_test_mul']['translatable'] = TRUE; + } } /** diff --git a/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php b/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php index a35e01ac4646bcf74c30cd4c52eb0284edd0b6a7..dcd596ecf39b72e83668880568f4718d19d44ca3 100644 --- a/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php +++ b/core/modules/content_translation/tests/src/Kernel/ContentTranslationEntityBundleInfoTest.php @@ -3,6 +3,8 @@ namespace Drupal\Tests\content_translation\Kernel; use Drupal\KernelTests\KernelTestBase; +use Drupal\entity_test\Entity\EntityTestMul; +use Drupal\language\Entity\ConfigurableLanguage; /** * Tests the Content Translation bundle info logic. @@ -40,6 +42,8 @@ protected function setUp() { $this->bundleInfo = $this->container->get('entity_type.bundle.info'); $this->installEntitySchema('entity_test_mul'); + + ConfigurableLanguage::createFromLangcode('it')->save(); } /** @@ -69,4 +73,18 @@ public function testHookInvocationOrder() { $this->assertTrue($state->get('content_translation_test.translatable')); } + /** + * Tests that field synchronization is skipped for disabled bundles. + */ + public function testFieldSynchronizationWithDisabledBundle() { + $entity = EntityTestMul::create(); + $entity->save(); + + /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */ + $translation = $entity->addTranslation('it'); + $translation->save(); + + $this->assertTrue($entity->isTranslatable()); + } + }