Issue #1832000 by Berdir: Fixed Entity translation metadata should be stored only for translation enabled entities/bundles.
parent
b7f577a2a8
commit
be073ff803
|
@ -67,4 +67,23 @@ class NodeTranslationUITest extends EntityTranslationUITest {
|
||||||
return array('title' => $this->title) + parent::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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,4 +86,17 @@ class TermTranslationUITest extends EntityTranslationUITest {
|
||||||
return array('name' => $this->name) + parent::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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,6 +500,11 @@ function translation_entity_load_translation_data(array $entities, $entity_type)
|
||||||
* Implements hook_entity_insert().
|
* Implements hook_entity_insert().
|
||||||
*/
|
*/
|
||||||
function translation_entity_entity_insert(EntityInterface $entity) {
|
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();
|
$entity_type = $entity->entityType();
|
||||||
$id = $entity->id();
|
$id = $entity->id();
|
||||||
$query = db_insert('translation_entity')
|
$query = db_insert('translation_entity')
|
||||||
|
@ -519,6 +524,11 @@ function translation_entity_entity_insert(EntityInterface $entity) {
|
||||||
* Implements hook_entity_delete().
|
* Implements hook_entity_delete().
|
||||||
*/
|
*/
|
||||||
function translation_entity_entity_delete(EntityInterface $entity) {
|
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')
|
db_delete('translation_entity')
|
||||||
->condition('entity_type', $entity->entityType())
|
->condition('entity_type', $entity->entityType())
|
||||||
->condition('entity_id', $entity->id())
|
->condition('entity_id', $entity->id())
|
||||||
|
@ -529,6 +539,11 @@ function translation_entity_entity_delete(EntityInterface $entity) {
|
||||||
* Implements hook_entity_update().
|
* Implements hook_entity_update().
|
||||||
*/
|
*/
|
||||||
function translation_entity_entity_update(EntityInterface $entity) {
|
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.
|
// Delete and create to ensure no stale value remains behind.
|
||||||
translation_entity_entity_delete($entity);
|
translation_entity_entity_delete($entity);
|
||||||
translation_entity_entity_insert($entity);
|
translation_entity_entity_insert($entity);
|
||||||
|
|
Loading…
Reference in New Issue