diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index ce905f9d58ce122229d41d1dedf85a5992a8f7db..501c7b78345956beaa58f3e3d02a596ac724c21c 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -141,6 +141,34 @@ public function prepareRow(Row $row) { ->condition('machine_name', $vocabulary, 'IN'); $allowed_vid = $query->execute()->fetchAllAssoc('vid'); $row->setSourceProperty('allowed_vid', $allowed_vid); + + // If there is an i18n_mode use it to determine if this field is + // translatable. It is TRUE only for i18n_mode 'Translate', all others are + // FALSE. When there is a term reference field with two vocabularies where + // one vocabulary is translatable and other is not the field itself is set + // to not translatable. Note mode '5' is not used for taxonomy but is + // listed here for completeness. + // - 0: No multilingual options. + // - 1: Localize. Localizable object. + // - 2: Fixed Language. + // - 4: Translate. Multilingual objects. + // - 5: Objects are translatable, if they have language or localizable + // if not) + if ($this->getDatabase() + ->schema() + ->fieldExists('taxonomy_vocabulary', 'i18n_mode')) { + $query = $this->select('taxonomy_vocabulary', 'v') + ->fields('v', ['i18n_mode']) + ->condition('machine_name', $vocabulary, 'IN'); + $results = $query->execute()->fetchAllAssoc('i18n_mode'); + $translatable = TRUE; + foreach ($results as $result) { + if ($result['i18n_mode'] != '4') { + $translatable = FALSE; + } + } + $row->setSourceProperty('translatable', $translatable); + } } $field_data = unserialize($row->getSourceProperty('field_data')); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php index ab73909171aeba682551f15b0b139ac639a3092e..ed70c74415e3b43e95852a8f4bdabbbc45523567 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php @@ -104,7 +104,7 @@ public function testFieldInstances() { $this->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE, FALSE); $this->assertEntity('comment.comment_node_article.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.article.body', 'Body', 'text_with_summary', FALSE, TRUE); - $this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE, TRUE); + $this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE, FALSE); $this->assertEntity('node.article.field_image', 'Image', 'image', FALSE, TRUE); $this->assertEntity('comment.comment_node_blog.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('node.blog.body', 'Body', 'text_with_summary', FALSE, TRUE); @@ -150,6 +150,11 @@ public function testFieldInstances() { $this->assertNull($name_field); $description_field = FieldConfig::load('taxonomy_term.test_vocabulary.description_field'); $this->assertNull($description_field); + + // Test the translation settings for taxonomy fields. + $this->assertEntity('node.article.field_vocab_fixed', 'vocab_fixed', 'entity_reference', FALSE, FALSE); + $this->assertEntity('node.article.field_vocab_localize', 'vocab_localize', 'entity_reference', FALSE, FALSE); + $this->assertEntity('node.article.field_vocab_translate', 'vocab_translate', 'entity_reference', FALSE, TRUE); } /** diff --git a/core/modules/language/migrations/d7_language_content_taxonomy_vocabulary_settings.yml b/core/modules/language/migrations/d7_language_content_taxonomy_vocabulary_settings.yml new file mode 100644 index 0000000000000000000000000000000000000000..39b72db86201a74154993765078484d073b8effd --- /dev/null +++ b/core/modules/language/migrations/d7_language_content_taxonomy_vocabulary_settings.yml @@ -0,0 +1,56 @@ +id: d7_language_content_taxonomy_vocabulary_settings +label: Drupal 7 language taxonomy vocabulary settings +migration_tags: + - Drupal 7 + - Configuration +source: + plugin: d7_language_content_settings_taxonomy_vocabulary + constants: + target_type: 'taxonomy_term' + default_langcode: 'site_default' +process: + target_bundle: + - + plugin: migration_lookup + migration: d7_taxonomy_vocabulary + source: vid + - + plugin: skip_on_empty + method: row + # State is the value in the i18n_mode column of taxonomy_vocabulary table + # 0: No multilingual options. + # 1: Localize. Localizable object. Run through the localization system + # 2: Fixed Language. Predefined language for this object and all related ones + # 4: Translate. Multilingual objects, translatable but not localizable. + # 5: Objects are translatable (if they have language or localizable if not) + # Note: the Drupal 6 Per-language value (3) changed to 4 in Drupal 7. + language_alterable: + plugin: static_map + source: i18n_mode + map: + 0: false + 1: true + 2: false + 4: true + 5: true + 'third_party_settings/content_translation/enabled': + plugin: static_map + source: i18n_mode + map: + 0: false + 1: true + 2: false + 4: false + 5: true + target_entity_type_id: 'constants/target_type' + default_langcode: + plugin: default_value + default_value: site_default + source: language +destination: + plugin: entity:language_content_settings + content_translation_update_definitions: + - taxonomy_term +migration_dependencies: + required: + - d7_taxonomy_vocabulary diff --git a/core/modules/language/migrations/state/language.migrate_drupal.yml b/core/modules/language/migrations/state/language.migrate_drupal.yml index 25ac491a22a11cc9d63ea4c3625a762c5ddfc567..3babdd9f0af2861edc4bab07bc8180336d5f2c49 100644 --- a/core/modules/language/migrations/state/language.migrate_drupal.yml +++ b/core/modules/language/migrations/state/language.migrate_drupal.yml @@ -1,11 +1,13 @@ finished: 6: + i18n_taxonomy: language locale: - language - system system: language taxonomy: language 7: + i18n_taxonomy: language locale: - language - system diff --git a/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettingsTaxonomyVocabulary.php b/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettingsTaxonomyVocabulary.php new file mode 100644 index 0000000000000000000000000000000000000000..eb2995062b665ec9a12f66a9628219a7a0dac437 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettingsTaxonomyVocabulary.php @@ -0,0 +1,41 @@ +<?php + +namespace Drupal\language\Plugin\migrate\source\d7; + +use Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary; + +/** + * Drupal 7 i18n vocabularies source from database. + * + * @MigrateSource( + * id = "d7_language_content_settings_taxonomy_vocabulary", + * source_module = "i18n_taxonomy" + * ) + */ +class LanguageContentSettingsTaxonomyVocabulary extends Vocabulary { + + /** + * {@inheritdoc} + */ + public function query() { + $query = parent::query(); + if ($this->getDatabase() + ->schema() + ->fieldExists('taxonomy_vocabulary', 'i18n_mode')) { + $query->addField('v', 'language'); + $query->addField('v', 'i18n_mode'); + } + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = parent::fields(); + $fields['language'] = $this->t('i18n language'); + $fields['i18n_mode'] = $this->t('i18n mode'); + return $fields; + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentTaxonomyVocabularySettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentTaxonomyVocabularySettingsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..5d43fec42e6b02a099307547a46637e1b7b222f0 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentTaxonomyVocabularySettingsTest.php @@ -0,0 +1,81 @@ +<?php + +namespace Drupal\Tests\language\Kernel\Migrate\d7; + +use Drupal\language\Entity\ContentLanguageSettings; +use Drupal\Core\Language\LanguageInterface; +use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; + +/** + * Tests migration of i18ntaxonomy vocabulary settings. + * + * @group migrate_drupal_7 + */ +class MigrateLanguageContentTaxonomyVocabularySettingsTest extends MigrateDrupal7TestBase { + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'language', + 'content_translation', + 'taxonomy', + 'text', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('taxonomy_term'); + $this->executeMigrations([ + 'language', + 'd7_taxonomy_vocabulary', + 'd7_language_content_taxonomy_vocabulary_settings', + ]); + } + + /** + * Tests migration of 18ntaxonomy vocabulary settings. + */ + public function testLanguageContentTaxonomy() { + $target_entity = 'taxonomy_term'; + // No multilingual options for terms, i18n_mode = 0. + $this->assertLanguageContentSettings($target_entity, 'tags', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]); + $this->assertLanguageContentSettings($target_entity, 'forums', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]); + $this->assertLanguageContentSettings($target_entity, 'vocabulary_name_much_longer_than', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]); + $this->assertLanguageContentSettings($target_entity, 'test_vocabulary', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]); + // Localize, i18n_mode = 1. + $this->assertLanguageContentSettings($target_entity, 'vocablocalized', LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE, ['enabled' => TRUE]); + // Translate, i18n_mode = 4. + $this->assertLanguageContentSettings($target_entity, 'vocabtranslate', LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE, ['enabled' => FALSE]); + // Fixed language, i18n_mode = 2. + $this->assertLanguageContentSettings($target_entity, 'vocabfixed', 'fr', FALSE, ['enabled' => FALSE]); + } + + /** + * Asserts a content language settings configuration. + * + * @param string $target_entity + * The expected target entity type. + * @param string $bundle + * The expected bundle. + * @param string $default_langcode + * The default language code. + * @param bool $language_alterable + * The expected state of language alterable. + * @param array $third_party_settings + * The content translation setting. + */ + public function assertLanguageContentSettings($target_entity, $bundle, $default_langcode, $language_alterable, array $third_party_settings) { + $config = ContentLanguageSettings::load($target_entity . '.' . $bundle); + $this->assertInstanceOf(ContentLanguageSettings::class, $config); + $this->assertSame($target_entity, $config->getTargetEntityTypeId()); + $this->assertSame($bundle, $config->getTargetBundle()); + $this->assertSame($default_langcode, $config->getDefaultLangcode()); + $this->assertSame($language_alterable, $config->isLanguageAlterable()); + $this->assertSame($third_party_settings, $config->getThirdPartySettings('content_translation')); + } + +} diff --git a/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d7/LanguageContentTaxonomyVocabularySettingsTest.php b/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d7/LanguageContentTaxonomyVocabularySettingsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..39762b59e01c1e899a14fd2e3a668e6ba6f51eb8 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Plugin/migrate/source/d7/LanguageContentTaxonomyVocabularySettingsTest.php @@ -0,0 +1,42 @@ +<?php + +namespace Drupal\Tests\language\Kernel\Plugin\migrate\source\d7; + +use Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d7\VocabularyTest; + +/** + * Tests i18ntaxonomy vocabulary setting source plugin. + * + * @covers \Drupal\language\Plugin\migrate\source\d7\LanguageContentSettingsTaxonomyVocabulary + * + * @group language + */ +class LanguageContentTaxonomyVocabularySettingsTest extends VocabularyTest { + + /** + * {@inheritdoc} + */ + public static $modules = ['taxonomy', 'language', 'migrate_drupal']; + + /** + * {@inheritdoc} + */ + public function providerSource() { + // Get the source data from parent. + $tests = parent::providerSource(); + + foreach ($tests as &$test) { + // Add the extra columns provided by i18n_taxonomy. + foreach ($test['source_data']['taxonomy_vocabulary'] as &$vocabulary) { + $vocabulary['language'] = 'und'; + $vocabulary['i18n_mode'] = 2; + } + foreach ($test['expected_data'] as &$expected) { + $expected['language'] = 'und'; + $expected['i18n_mode'] = 2; + } + } + return $tests; + } + +} diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php index 7e7bd5502a4881a63386c014568a2beb60e446e7..9d06bbcd2cde182c2d31a15e7e137c7aa9164d17 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php @@ -79,7 +79,7 @@ protected function getEntityCounts() { 'file' => 3, 'filter_format' => 7, 'image_style' => 6, - 'language_content_settings' => 11, + 'language_content_settings' => 17, 'node' => 6, 'node_type' => 6, 'rdf_mapping' => 8,