diff --git a/core/modules/content_translation/migrations/d7_taxonomy_term_entity_translation.yml b/core/modules/content_translation/migrations/d7_taxonomy_term_entity_translation.yml new file mode 100644 index 0000000000000000000000000000000000000000..f4ab6731bfa20e1318a96391557e8c4c3181e80a --- /dev/null +++ b/core/modules/content_translation/migrations/d7_taxonomy_term_entity_translation.yml @@ -0,0 +1,32 @@ +id: d7_taxonomy_term_entity_translation +label: Taxonomy term entity translations +migration_tags: + - Drupal 7 + - translation + - Content + - Multilingual +deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver +source: + plugin: d7_taxonomy_term_entity_translation +process: + tid: entity_id + name: name + description/value: description + description/format: format + langcode: language + status: status + content_translation_source: source + content_translation_outdated: translate + content_translation_uid: uid + content_translation_created: created + changed: changed + forum_container: is_container +destination: + plugin: entity:taxonomy_term + translations: true + destination_module: content_translation +migration_dependencies: + required: + - language + - d7_entity_translation_settings + - d7_taxonomy_term diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index fedfd38c506f9f58bd11710a6fe48988af04461a..cdacddb390ae37113900a958cd4139b8445692cf 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -3175,6 +3175,42 @@ 'created' => '1529615813', 'changed' => '1529615813', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'en', + 'source' => '', + 'uid' => '1', + 'status' => '1', + 'translate' => '0', + 'created' => '1531922259', + 'changed' => '1531922259', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'source' => 'en', + 'uid' => '2', + 'status' => '1', + 'translate' => '1', + 'created' => '1531922267', + 'changed' => '1531922268', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'source' => 'en', + 'uid' => '1', + 'status' => '0', + 'translate' => '0', + 'created' => '1531922278', + 'changed' => '1531922279', +)) ->values(array( 'entity_type' => 'user', 'entity_id' => '2', @@ -5050,10 +5086,34 @@ 'revision_id' => '4', 'language' => 'en', 'delta' => '0', - 'description_field_value' => 'The third term.', + 'description_field_value' => 'The third term in plain old English.', 'description_field_summary' => '', 'description_field_format' => 'full_html', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'description_field_value' => 'The third term en français s\'il vous plaît.', + 'description_field_summary' => '', + 'description_field_format' => 'filtered_html', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'description_field_value' => 'The third term á íslensku.', + 'description_field_summary' => '', + 'description_field_format' => 'plain_text', +)) ->execute(); $connection->schema()->createTable('field_data_field_boolean', array( @@ -6223,6 +6283,26 @@ 'delta' => '0', 'field_integer_value' => '6', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'field_integer_value' => '5', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'field_integer_value' => '4', +)) ->execute(); $connection->schema()->createTable('field_data_field_integer_list', array( @@ -8648,7 +8728,29 @@ 'revision_id' => '4', 'language' => 'en', 'delta' => '0', - 'name_field_value' => 'Term3', + 'name_field_value' => 'Term3 in plain old English', + 'name_field_format' => NULL, +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'name_field_value' => 'Term3 en français s\'il vous plaît', + 'name_field_format' => NULL, +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'name_field_value' => 'Term3 á íslensku', 'name_field_format' => NULL, )) ->execute(); @@ -9392,8 +9494,32 @@ 'revision_id' => '4', 'language' => 'en', 'delta' => '0', - 'description_field_value' => 'The third term.', - 'description_field_summary' => NULL, + 'description_field_value' => 'The third term in plain old English.', + 'description_field_summary' => '', + 'description_field_format' => 'full_html', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'description_field_value' => 'The third term en français s\'il vous plaît.', + 'description_field_summary' => '', + 'description_field_format' => 'full_html', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'description_field_value' => 'The third term á íslensku.', + 'description_field_summary' => '', 'description_field_format' => 'full_html', )) ->execute(); @@ -10557,6 +10683,26 @@ 'delta' => '0', 'field_integer_value' => '6', )) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'field_integer_value' => '5', +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'field_integer_value' => '4', +)) ->execute(); $connection->schema()->createTable('field_revision_field_integer_list', array( @@ -13015,7 +13161,29 @@ 'revision_id' => '4', 'language' => 'en', 'delta' => '0', - 'name_field_value' => 'Term3', + 'name_field_value' => 'Term3 in plain old English', + 'name_field_format' => NULL, +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'fr', + 'delta' => '0', + 'name_field_value' => 'Term3 en français s\'il vous plaît', + 'name_field_format' => NULL, +)) +->values(array( + 'entity_type' => 'taxonomy_term', + 'bundle' => 'test_vocabulary', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'is', + 'delta' => '0', + 'name_field_value' => 'Term3 á íslensku', 'name_field_format' => NULL, )) ->execute(); diff --git a/core/modules/taxonomy/migrations/d7_taxonomy_term.yml b/core/modules/taxonomy/migrations/d7_taxonomy_term.yml index 0331cf057253ef4580ae7ec985c30aa7f4a0df7e..1bae2d6e32f9d8e6903d3db377b88c16164b877c 100644 --- a/core/modules/taxonomy/migrations/d7_taxonomy_term.yml +++ b/core/modules/taxonomy/migrations/d7_taxonomy_term.yml @@ -34,6 +34,7 @@ process: source: '@parent_id' forum_container: is_container changed: timestamp + langcode: language destination: plugin: entity:taxonomy_term migration_dependencies: diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php index 658f4422b48014e527d605355b9fff6b25c35bd9..18d94ff5d0920aa22e2b8dfe102634619d51f820 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php @@ -56,10 +56,26 @@ public function fields() { * {@inheritdoc} */ public function prepareRow(Row $row) { + $tid = $row->getSourceProperty('tid'); + $vocabulary = $row->getSourceProperty('machine_name'); + $default_language = (array) $this->variableGet('language_default', ['language' => 'en']); + + // If this entity was translated using Entity Translation, we need to get + // its source language to get the field values in the right language. + // The translations will be migrated by the d7_node_entity_translation + // migration. + $translatable_vocabularies = array_keys(array_filter($this->variableGet('entity_translation_taxonomy', []))); + $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']; + $row->setSourceProperty('language', $language); + // Get Field API field values. - foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { - $tid = $row->getSourceProperty('tid'); - $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) { + // Ensure we're using the right language if the entity and the field are + // translatable. + $field_language = $entity_translatable && $field['translatable'] ? $language : NULL; + $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language)); } // Find parents for this row. @@ -87,6 +103,9 @@ public function prepareRow(Row $row) { if (isset($description_field[0]['value'])) { $row->setSourceProperty('description', $description_field[0]['value']); } + if (isset($description_field[0]['format'])) { + $row->setSourceProperty('format', $description_field[0]['format']); + } } return parent::prepareRow($row); diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php new file mode 100644 index 0000000000000000000000000000000000000000..0ba70c8d2b03eea797a68f4e75f93665637bbb1a --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermEntityTranslation.php @@ -0,0 +1,122 @@ +select('entity_translation', 'et') + ->fields('et') + ->fields('td', [ + 'name', + 'description', + 'format', + ]) + ->fields('tv', [ + 'machine_name', + ]) + ->condition('et.entity_type', 'taxonomy_term') + ->condition('et.source', '', '<>'); + + $query->innerJoin('taxonomy_term_data', 'td', 'td.tid = et.entity_id'); + $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $tid = $row->getSourceProperty('entity_id'); + $vocabulary = $row->getSourceProperty('machine_name'); + $language = $row->getSourceProperty('language'); + + // Get Field API field values. + foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) { + // Ensure we're using the right language if the entity is translatable. + $field_language = $field['translatable'] ? $language : NULL; + $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, NULL, $field_language)); + } + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + if ($this->moduleExists('title')) { + $name_field = $row->getSourceProperty('name_field'); + if (isset($name_field[0]['value'])) { + $row->setSourceProperty('name', $name_field[0]['value']); + } + $description_field = $row->getSourceProperty('description_field'); + if (isset($description_field[0]['value'])) { + $row->setSourceProperty('description', $description_field[0]['value']); + } + if (isset($description_field[0]['format'])) { + $row->setSourceProperty('format', $description_field[0]['format']); + } + } + + // Determine if this is a forum container. + $forum_container_tids = $this->variableGet('forum_containers', []); + $row->setSourceProperty('is_container', in_array($tid, $forum_container_tids)); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'entity_type' => $this->t('The entity type this translation relates to'), + 'entity_id' => $this->t('The entity ID this translation relates to'), + 'revision_id' => $this->t('The entity revision ID this translation relates to'), + 'language' => $this->t('The target language for this translation.'), + 'source' => $this->t('The source language from which this translation was created.'), + 'uid' => $this->t('The author of this translation.'), + 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'), + 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'), + 'created' => $this->t('The Unix timestamp when the translation was created.'), + 'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'format' => $this->t('Format of the term description.'), + 'machine_name' => $this->t('Vocabulary machine name'), + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return [ + 'entity_id' => [ + 'type' => 'integer', + 'alias' => 'et', + ], + 'language' => [ + 'type' => 'string', + 'alias' => 'et', + ], + ]; + } + +} diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index 85a64b00d2bc0467583f7d86cef114c1eaf0843d..8a7d912571179e797691a16e3676c73134304a29 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -15,11 +15,15 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { public static $modules = [ 'comment', + 'content_translation', 'datetime', 'forum', 'image', + 'language', 'link', 'menu_ui', + // Required for translation migrations. + 'migrate_drupal_multilingual', 'node', 'taxonomy', 'telephone', @@ -38,16 +42,23 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); + $this->installEntitySchema('comment'); + $this->installEntitySchema('node'); $this->installEntitySchema('taxonomy_term'); $this->installConfig(static::$modules); $this->executeMigrations([ + 'language', + 'd7_user_role', + 'd7_user', 'd7_node_type', 'd7_comment_type', 'd7_field', 'd7_taxonomy_vocabulary', 'd7_field_instance', 'd7_taxonomy_term', + 'd7_entity_translation_settings', + 'd7_taxonomy_term_entity_translation', ]); } @@ -110,7 +121,7 @@ public function testTaxonomyTerms() { $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(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html'); - $this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6); + $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]); @@ -162,4 +173,56 @@ protected function assertHierarchy($vid, $tid, array $parent_ids) { $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); } + /** + * Tests the migration of taxonomy term entity translations. + */ + public function testTaxonomyTermEntityTranslations() { + $manager = $this->container->get('content_translation.manager'); + + // Get the term and its translations. + $term = Term::load(4); + $term_fr = $term->getTranslation('fr'); + $term_is = $term->getTranslation('is'); + + // Test that fields translated with Entity Translation are migrated. + $this->assertSame('Term3 in plain old English', $term->getName()); + $this->assertSame('Term3 en français s\'il vous plaît', $term_fr->getName()); + $this->assertSame('Term3 á íslensku', $term_is->getName()); + $this->assertSame('The third term in plain old English.', $term->getDescription()); + $this->assertSame('The third term en français s\'il vous plaît.', $term_fr->getDescription()); + $this->assertSame('The third term á íslensku.', $term_is->getDescription()); + $this->assertSame('full_html', $term->getFormat()); + $this->assertSame('filtered_html', $term_fr->getFormat()); + $this->assertSame('plain_text', $term_is->getFormat()); + $this->assertSame('6', $term->field_integer->value); + $this->assertSame('5', $term_fr->field_integer->value); + $this->assertSame('4', $term_is->field_integer->value); + + // Test that the French translation metadata is correctly migrated. + $metadata_fr = $manager->getTranslationMetadata($term_fr); + $this->assertTrue($metadata_fr->isPublished()); + $this->assertSame('en', $metadata_fr->getSource()); + $this->assertSame('2', $metadata_fr->getAuthor()->uid->value); + $this->assertSame('1531922267', $metadata_fr->getCreatedTime()); + $this->assertSame('1531922268', $metadata_fr->getChangedTime()); + $this->assertTrue($metadata_fr->isOutdated()); + + // Test that the Icelandic translation metadata is correctly migrated. + $metadata_is = $manager->getTranslationMetadata($term_is); + $this->assertFalse($metadata_is->isPublished()); + $this->assertSame('en', $metadata_is->getSource()); + $this->assertSame('1', $metadata_is->getAuthor()->uid->value); + $this->assertSame('1531922278', $metadata_is->getCreatedTime()); + $this->assertSame('1531922279', $metadata_is->getChangedTime()); + $this->assertFalse($metadata_is->isOutdated()); + + // Test that untranslatable properties are the same as the source language. + $this->assertSame($term->bundle(), $term_fr->bundle()); + $this->assertSame($term->bundle(), $term_is->bundle()); + $this->assertSame($term->getWeight(), $term_fr->getWeight()); + $this->assertSame($term->getWeight(), $term_is->getWeight()); + $this->assertSame($term->parent->terget_id, $term_fr->parent->terget_id); + $this->assertSame($term->parent->terget_id, $term_is->parent->terget_id); + } + } diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermEntityTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermEntityTranslationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3a9145171371f1dc3269f3d5e3a1041714838ce1 --- /dev/null +++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermEntityTranslationTest.php @@ -0,0 +1,334 @@ + 'taxonomy_term', + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'en', + 'source' => '', + 'uid' => 1, + 'status' => 1, + 'translate' => 0, + 'created' => 1531343498, + 'changed' => 1531343498, + ], + [ + 'entity_type' => 'taxonomy_term', + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'fr', + 'source' => 'en', + 'uid' => 2, + 'status' => 1, + 'translate' => 1, + 'created' => 1531343508, + 'changed' => 1531343508, + ], + [ + 'entity_type' => 'taxonomy_term', + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'es', + 'source' => 'en', + 'uid' => 1, + 'status' => 0, + 'translate' => 0, + 'created' => 1531343528, + 'changed' => 1531343528, + ], + ]; + $tests[0]['source_data']['field_config'] = [ + [ + 'id' => 1, + 'field_name' => 'field_test', + 'type' => 'text', + 'module' => 'text', + 'active' => 1, + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => 1, + 'locked' => 1, + 'data' => 'a:0:{}', + 'cardinality' => 1, + 'translatable' => 1, + 'deleted' => 0, + ], + [ + 'id' => 2, + 'field_name' => 'name_field', + 'type' => 'text', + 'module' => 'text', + 'active' => 1, + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => 1, + 'locked' => 1, + 'data' => 'a:0:{}', + 'cardinality' => 1, + 'translatable' => 1, + 'deleted' => 0, + ], + [ + 'id' => 3, + 'field_name' => 'description_field', + 'type' => 'text', + 'module' => 'text', + 'active' => 1, + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => 1, + 'locked' => 1, + 'data' => 'a:0:{}', + 'cardinality' => 1, + 'translatable' => 1, + 'deleted' => 0, + ], + ]; + $tests[0]['source_data']['field_config_instance'] = [ + [ + 'id' => '1', + 'field_id' => 1, + 'field_name' => 'field_test', + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'data' => 'a:0:{}', + 'deleted' => 0, + ], + [ + 'id' => 2, + 'field_id' => 2, + 'field_name' => 'name_field', + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'data' => 'a:0:{}', + 'deleted' => 0, + ], + [ + 'id' => 3, + 'field_id' => 3, + 'field_name' => 'description_field', + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'data' => 'a:0:{}', + 'deleted' => 0, + ], + ]; + $tests[0]['source_data']['field_data_field_test'] = [ + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => 0, + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'en', + 'delta' => 0, + 'field_test_value' => 'English field', + 'field_test_format' => 'filtered_html', + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => 0, + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'fr', + 'delta' => 0, + 'field_test_value' => 'French field', + 'field_test_format' => 'filtered_html', + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => 0, + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'es', + 'delta' => 0, + 'field_test_value' => 'Spanish field', + 'field_test_format' => 'filtered_html', + ], + ]; + $tests[0]['source_data']['field_data_name_field'] = [ + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'en', + 'delta' => '0', + 'name_field_value' => 'Term Name EN', + 'name_field_format' => NULL, + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'fr', + 'delta' => '0', + 'name_field_value' => 'Term Name FR', + 'name_field_format' => NULL, + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'es', + 'delta' => '0', + 'name_field_value' => 'Term Name ES', + 'name_field_format' => NULL, + ], + ]; + $tests[0]['source_data']['field_data_description_field'] = [ + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'en', + 'delta' => '0', + 'description_field_value' => 'Term Description EN', + 'description_field_format' => 'full_html', + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'fr', + 'delta' => '0', + 'description_field_value' => 'Term Description FR', + 'description_field_format' => 'full_html', + ], + [ + 'entity_type' => 'taxonomy_term', + 'bundle' => 'tags', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'es', + 'delta' => '0', + 'description_field_value' => 'Term Description ES', + 'description_field_format' => 'full_html', + ], + ]; + $tests[0]['source_data']['system'] = [ + [ + 'name' => 'title', + 'type' => 'module', + 'status' => 1, + ], + ]; + $tests[0]['source_data']['taxonomy_term_data'] = [ + [ + 'tid' => 1, + 'vid' => 1, + 'name' => 'Term Name', + 'description' => 'Term Description', + 'format' => 'filtered_html', + 'weight' => 0, + ], + ]; + $tests[0]['source_data']['taxonomy_term_hierarchy'] = [ + [ + 'tid' => 1, + 'parent' => 0, + ], + ]; + $tests[0]['source_data']['taxonomy_vocabulary'] = [ + [ + 'vid' => 1, + 'name' => 'Tags', + 'machine_name' => 'tags', + 'description' => '', + 'hierarchy' => 0, + 'module' => 'taxonomy', + 'weight' => 0, + ], + ]; + + // The expected results. + $tests[0]['expected_data'] = [ + [ + 'entity_type' => 'taxonomy_term', + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'fr', + 'source' => 'en', + 'uid' => 2, + 'status' => 1, + 'translate' => 1, + 'created' => 1531343508, + 'changed' => 1531343508, + 'name' => 'Term Name FR', + 'description' => 'Term Description FR', + 'format' => 'full_html', + 'machine_name' => 'tags', + 'is_container' => FALSE, + 'field_test' => [ + [ + 'value' => 'French field', + 'format' => 'filtered_html', + ], + ], + ], + [ + 'entity_type' => 'taxonomy_term', + 'entity_id' => 1, + 'revision_id' => 1, + 'language' => 'es', + 'source' => 'en', + 'uid' => 1, + 'status' => 0, + 'translate' => 0, + 'created' => 1531343528, + 'changed' => 1531343528, + 'name' => 'Term Name ES', + 'description' => 'Term Description ES', + 'format' => 'full_html', + 'machine_name' => 'tags', + 'is_container' => FALSE, + 'field_test' => [ + [ + 'value' => 'Spanish field', + 'format' => 'filtered_html', + ], + ], + ], + ]; + + return $tests; + } + +} diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php index ef002cfec89b3270d9e7a4522d17e0f8e4e0985a..0466d750e9d0d79bd0ea0fbec9b40a63f30d02c0 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermTest.php @@ -254,6 +254,10 @@ public function providerSource() { 'name' => 'forum_containers', 'value' => 'a:3:{i:0;s:1:"5";i:1;s:1:"6";i:2;s:1:"7";}', ], + [ + 'name' => 'language_default', + 'value' => 'O:8:"stdClass":1:{s:8:"language";s:2:"en";}', + ], ]; // The expected results. @@ -265,6 +269,7 @@ public function providerSource() { 'description' => 'description value 1 (description_field)', 'weight' => 0, 'parent' => [0], + 'language' => 'en', ], [ 'tid' => 2, @@ -273,6 +278,7 @@ public function providerSource() { 'description' => 'description value 2', 'weight' => 0, 'parent' => [0], + 'language' => 'en', ], [ 'tid' => 3, @@ -281,6 +287,7 @@ public function providerSource() { 'description' => 'description value 3', 'weight' => 0, 'parent' => [0], + 'language' => 'en', ], [ 'tid' => 4, @@ -289,6 +296,7 @@ public function providerSource() { 'description' => 'description value 4 (description_field)', 'weight' => 1, 'parent' => [1], + 'language' => 'en', ], [ 'tid' => 5, @@ -297,6 +305,7 @@ public function providerSource() { 'description' => 'description value 5', 'weight' => 1, 'parent' => [2], + 'language' => 'en', ], [ 'tid' => 6, @@ -305,6 +314,7 @@ public function providerSource() { 'description' => 'description value 6', 'weight' => 0, 'parent' => [3, 2], + 'language' => 'en', ], [ 'tid' => 7, @@ -313,6 +323,7 @@ public function providerSource() { 'description' => 'description value 7', 'weight' => 0, 'parent' => [0], + 'language' => 'en', ], ]; @@ -330,6 +341,7 @@ public function providerSource() { 'description' => 'description value 1 (description_field)', 'weight' => 0, 'parent' => [0], + 'language' => 'en', ], [ 'tid' => 4, @@ -338,6 +350,7 @@ public function providerSource() { 'description' => 'description value 4 (description_field)', 'weight' => 1, 'parent' => [1], + 'language' => 'en', ], ]; $tests[1]['expected_count'] = NULL;