Commit fb4d8966 authored by effulgentsia's avatar effulgentsia
Browse files

Issue #2939917 by plach, jibran, Wim Leers: Field synchronization should run...

Issue #2939917 by plach, jibran, Wim Leers: Field synchronization should run only for Content Translation-enabled entities
parent bc1fc2f7
......@@ -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);
}
......
......@@ -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;
}
}
/**
......
......@@ -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());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment