Unverified Commit 32f4d3e4 authored by larowlan's avatar larowlan

Issue #2979966 by quietone, PieterDC, masipila, Gábor Hojtsy, heddn, alexpott:...

Issue #2979966 by quietone, PieterDC, masipila, Gábor Hojtsy, heddn, alexpott: Migrate D7 i18n taxonomy term language
parent 86719fc9
......@@ -28,6 +28,12 @@ public function query() {
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
$query->addField('tv', 'machine_name');
if ($this->getDatabase()
->schema()
->fieldExists('taxonomy_vocabulary', 'i18n_mode')) {
$query->addField('tv', 'i18n_mode');
}
if (isset($this->configuration['bundle'])) {
$query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
}
......@@ -68,6 +74,12 @@ public function prepareRow(Row $row) {
$entity_translatable = $this->isEntityTranslatable('taxonomy_term') && in_array($vocabulary, $translatable_vocabularies, TRUE);
$source_language = $this->getEntityTranslationSourceLanguage('taxonomy_term', $tid);
$language = $entity_translatable && $source_language ? $source_language : $default_language['language'];
// If this is an i18n translation use the default language when i18n_mode
// is localized.
if ($row->get('i18n_mode')) {
$language = ($row->get('i18n_mode') === '1') ? $default_language['language'] : $row->get('language');
}
$row->setSourceProperty('language', $language);
// Get Field API field values.
......
......@@ -59,6 +59,8 @@ protected function setUp() {
*
* @param $id
* Entity ID to load and check.
* @param string $expected_language
* The language code for this term.
* @param $expected_label
* The label the migrated entity should have.
* @param $expected_vid
......@@ -78,10 +80,11 @@ protected function setUp() {
* @param bool $expected_container_flag
* The term should be a container entity.
*/
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = 0) {
protected function assertEntity($id, $expected_language, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, array $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = 0) {
/** @var \Drupal\taxonomy\TermInterface $entity */
$entity = Term::load($id);
$this->assertInstanceOf(TermInterface::class, $entity);
$this->assertSame($expected_language, $entity->language()->getId());
$this->assertEquals($expected_label, $entity->label());
$this->assertEquals($expected_vid, $entity->bundle());
$this->assertEquals($expected_description, $entity->getDescription());
......@@ -106,18 +109,18 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d
* Tests the Drupal 7 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$this->assertEntity(1, 'General discussion', 'forums', '', NULL, 2);
$this->assertEntity(1, 'en', 'General discussion', 'forums', '', NULL, 2);
// Tests that terms that used the Drupal 7 Title module and that have their
// name and description replaced by real fields are correctly migrated.
$this->assertEntity(2, 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
$this->assertEntity(2, 'en', 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3 in plain old English', 'test_vocabulary', 'The third term in plain old English.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'Games', 'forums', '', NULL, 4, [], NULL, NULL, 1);
$this->assertEntity(7, 'Minecraft', 'forums', '', NULL, 1, [6]);
$this->assertEntity(8, 'Half Life 3', 'forums', '', NULL, 0, [6]);
$this->assertEntity(3, 'en', 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'en', 'Term3 in plain old English', 'test_vocabulary', 'The third term in plain old English.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'en', 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
$this->assertEntity(6, 'en', 'Games', 'forums', NULL, '', 4, []);
$this->assertEntity(7, 'en', 'Minecraft', 'forums', '', NULL, 1, [6]);
$this->assertEntity(8, 'en', 'Half Life 3', 'forums', '', NULL, 0, [6]);
// Verify that we still can create forum containers after the migration.
$term = Term::create(['vid' => 'forums', 'name' => 'Forum Container', 'forum_container' => 1]);
......@@ -125,7 +128,15 @@ public function testTaxonomyTerms() {
// Reset the forums tree data so this new term is included in the tree.
unset($this->treeData['forums']);
$this->assertEntity(25, 'Forum Container', 'forums', '', NULL, 0, [], NULL, NULL, 1);
$this->assertEntity(25, 'en', 'Forum Container', 'forums', '', '', 0, [], NULL, NULL, 1);
// Test taxonomy term language translations.
$this->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', 0, [], NULL, NULL, 1);
$this->assertEntity(20, 'en', 'DS9', 'vocablocalized', 'Terok Nor', 'filtered_html', 0, [], NULL, NULL, 1);
$this->assertEntity(21, 'en', 'High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
$this->assertEntity(22, 'fr', 'fr - High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
$this->assertEntity(23, 'is', 'is - High council', 'vocabtranslate', NULL, NULL, 0, [], NULL, NULL, 1);
$this->assertEntity(24, 'fr', 'FR - Crewman', 'vocabfixed', NULL, NULL, 0, [], NULL, NULL, 1);
}
/**
......
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