diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 17c7fec..5fda368 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -67,4 +67,23 @@ protected function getNewEntityValues($langcode) { return array('title' => $this->title) + parent::getNewEntityValues($langcode); } + /** + * Test that no metadata is stored for a disabled bundle. + */ + public function testDisabledBundle() { + // Create a bundle that does not have translation enabled. + $disabledBundle = $this->randomName(); + $this->drupalCreateContentType(array('type' => $disabledBundle, 'name' => $disabledBundle)); + + // Create a node for each bundle. + $enabledNode = $this->drupalCreateNode(array('type' => $this->bundle)); + $disabledNode = $this->drupalCreateNode(array('type' => $disabledBundle)); + + // Make sure that only a single row was inserted into the + // {translation_entity} table. + $rows = db_query('SELECT * FROM {translation_entity}')->fetchAll(); + $this->assertEqual(1, count($rows)); + $this->assertEqual($enabledNode->id(), reset($rows)->entity_id); + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php index 907ce87..90982f4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php @@ -86,4 +86,17 @@ protected function getNewEntityValues($langcode) { return array('name' => $this->name) + parent::getNewEntityValues($langcode); } + /** + * Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::testTranslationUI(). + */ + public function testTranslationUI() { + parent::testTranslationUI(); + + // Make sure that no row was inserted for taxonomy vocabularies, which do + // not have translations enabled. + $rows = db_query('SELECT * FROM {translation_entity}')->fetchAll(); + $this->assertEqual(2, count($rows)); + $this->assertEqual('taxonomy_term', $rows[0]->entity_type); + $this->assertEqual('taxonomy_term', $rows[1]->entity_type); + } } diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index b0c8526..f57773b 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -500,6 +500,11 @@ function translation_entity_load_translation_data(array $entities, $entity_type) * Implements hook_entity_insert(). */ function translation_entity_entity_insert(EntityInterface $entity) { + // Only do something if translation support for the given entity is enabled. + if (!translation_entity_enabled($entity->entityType(), $entity->bundle())) { + return; + } + $entity_type = $entity->entityType(); $id = $entity->id(); $query = db_insert('translation_entity') @@ -519,6 +524,11 @@ function translation_entity_entity_insert(EntityInterface $entity) { * Implements hook_entity_delete(). */ function translation_entity_entity_delete(EntityInterface $entity) { + // Only do something if translation support for the given entity is enabled. + if (!translation_entity_enabled($entity->entityType(), $entity->bundle())) { + return; + } + db_delete('translation_entity') ->condition('entity_type', $entity->entityType()) ->condition('entity_id', $entity->id()) @@ -529,6 +539,11 @@ function translation_entity_entity_delete(EntityInterface $entity) { * Implements hook_entity_update(). */ function translation_entity_entity_update(EntityInterface $entity) { + // Only do something if translation support for the given entity is enabled. + if (!translation_entity_enabled($entity->entityType(), $entity->bundle())) { + return; + } + // Delete and create to ensure no stale value remains behind. translation_entity_entity_delete($entity); translation_entity_entity_insert($entity);