diff --git a/core/modules/language/migration_templates/d6_language_content_settings.yml b/core/modules/language/migration_templates/d6_language_content_settings.yml new file mode 100644 index 0000000..e5dc750 --- /dev/null +++ b/core/modules/language/migration_templates/d6_language_content_settings.yml @@ -0,0 +1,44 @@ +id: d6_language_content_settings +label: Drupal 6 language content settings +migration_tags: + - Drupal 6 +source: + plugin: d6_language_content_settings + constants: + target_type: 'node' +process: +# Ignore i18n_node_options_[node_type] options not available in Drupal 8, +# i18n_required_node and i18n_newnode_current + target_bundle: type + target_entity_type_id: 'constants/target_type' + default_langcode: + - + plugin: static_map + source: language_content_type + map: + 0: NULL + 1: 'current_interface' + 2: 'current_interface' + - + plugin: skip_on_empty + method: row + language_alterable: + plugin: static_map + source: i18n_lock_node + map: + 0: true + 1: false + 'third_party_settings/content_translation/enabled': + plugin: static_map + source: language_content_type + map: + # In the case of being 0, it will be skipped. We are not actually setting + # a null value. + 0: NULL + 1: false + 2: true +destination: + plugin: entity:language_content_settings +migration_dependencies: + required: + - d6_node_type diff --git a/core/modules/language/migration_templates/d7_language_content_settings.yml b/core/modules/language/migration_templates/d7_language_content_settings.yml new file mode 100644 index 0000000..cbe935a --- /dev/null +++ b/core/modules/language/migration_templates/d7_language_content_settings.yml @@ -0,0 +1,44 @@ +id: d7_language_content_settings +label: Drupal 7 language content settings +migration_tags: + - Drupal 7 +source: + plugin: d7_language_content_settings + constants: + target_type: 'node' +process: +# Ignore i18n_node_options_[node_type] options not available in Drupal 8, +# i18n_required_node and i18n_newnode_current + target_bundle: type + target_entity_type_id: 'constants/target_type' + default_langcode: + - + plugin: static_map + source: language_content_type + map: + 0: NULL + 1: 'current_interface' + 2: 'current_interface' + - + plugin: skip_on_empty + method: row + language_alterable: + plugin: static_map + source: i18n_lock_node + map: + 0: true + 1: false + 'third_party_settings/content_translation/enabled': + plugin: static_map + source: language_content_type + map: + # In the case of being 0, it will be skipped. We are not actually setting + # a null value. + 0: NULL + 1: false + 2: true +destination: + plugin: entity:language_content_settings +migration_dependencies: + required: + - d7_node_type diff --git a/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettings.php b/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettings.php new file mode 100644 index 0000000..c41b635 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/source/d6/LanguageContentSettings.php @@ -0,0 +1,57 @@ +select('node_type', 't') + ->fields('t', array( + 'type', + )); + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = array( + 'type' => $this->t('Type'), + 'language_content_type' => $this->t('Multilingual support.'), + 'i18n_lock_node' => $this->t('Lock language.'), + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $type = $row->getSourceProperty('type'); + $row->setSourceProperty('language_content_type', $this->variableGet('language_content_type_' . $type, NULL)); + $row->setSourceProperty('i18n_lock_node', $this->variableGet('i18n_lock_node_' . $type, 0)); + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['type']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettings.php b/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettings.php new file mode 100644 index 0000000..91ed020 --- /dev/null +++ b/core/modules/language/src/Plugin/migrate/source/d7/LanguageContentSettings.php @@ -0,0 +1,63 @@ +select('node_type', 't') + ->fields('t', array( + 'type', + )); + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = array( + 'type' => $this->t('Type'), + 'language_content_type' => $this->t('Multilingual support.'), + 'i18n_lock_node' => $this->t('Lock language.'), + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $type = $row->getSourceProperty('type'); + $row->setSourceProperty('language_content_type', $this->variableGet('language_content_type_' . $type, NULL)); + $i18n_node_options = $this->variableGet('i18n_node_options_' . $type, NULL); + if ($i18n_node_options && in_array('lock', $i18n_node_options)) { + $row->setSourceProperty('i18n_lock_node', 1); + } + else { + $row->setSourceProperty('i18n_lock_node', 0); + } + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['type']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php new file mode 100644 index 0000000..0420d70 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentSettingsTest.php @@ -0,0 +1,59 @@ +installConfig(['node']); + $this->executeMigrations(['d6_node_type', 'd6_language_content_settings']); + } + + /** + * Tests migration of content language settings. + */ + public function testLanguageContent() { + // Assert that a translatable content is still translatable. + $config = $this->config('language.content_settings.node.article'); + $this->assertSame($config->get('target_entity_type_id'), 'node'); + $this->assertSame($config->get('target_bundle'), 'article'); + $this->assertSame($config->get('default_langcode'), 'current_interface'); + $this->assertTrue($config->get('third_party_settings.content_translation.enabled')); + + // Assert that a non-translatable content is not translatable. + $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'company'); + $this->assertTrue($config->isDefaultConfiguration()); + $this->assertFalse($config->isLanguageAlterable()); + $this->assertSame($config->getDefaultLangcode(), 'site_default'); + } + + /** + * Tests migration of content language settings when there is no language lock. + */ + public function testLanguageContentWithNoLanguageLock() { + // Assert that a we can assign a language. + $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee'); + $this->assertSame($config->getDefaultLangcode(), 'current_interface'); + $this->assertTrue($config->isLanguageAlterable()); + } + +} diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php new file mode 100644 index 0000000..defc6cd --- /dev/null +++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentSettingsTest.php @@ -0,0 +1,50 @@ +installConfig(['node']); + $this->executeMigrations(['d7_node_type', 'd7_language_content_settings']); + } + + /** + * Tests migration of content language settings. + */ + public function testLanguageContent() { + // Assert that a translatable content is still translatable. + $config = $this->config('language.content_settings.node.blog'); + $this->assertIdentical($config->get('target_entity_type_id'), 'node'); + $this->assertIdentical($config->get('target_bundle'), 'blog'); + $this->assertIdentical($config->get('default_langcode'), 'current_interface'); + $this->assertFalse($config->get('language_alterable')); + $this->assertTrue($config->get('third_party_settings.content_translation.enabled')); + + // Assert that a non-translatable content is not translatable. + $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page'); + $this->assertTrue($config->isDefaultConfiguration()); + $this->assertFalse($config->isLanguageAlterable()); + $this->assertSame($config->getDefaultLangcode(), 'site_default'); + + } + +} diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 4242cad..7d1c020 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -45534,6 +45534,14 @@ 'value' => 's:1:"2";', )) ->values(array( + 'name' => 'language_content_type_employee', + 'value' => 's:1:"2";', +)) +->values(array( + 'name' => 'i18n_lock_node_article', + 'value' => 'i:1;', +)) +->values(array( 'name' => 'language_count', 'value' => 'i:11;', )) diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 2797b6c..258821f 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -41323,6 +41323,10 @@ 'value' => 's:1:"0";', )) ->values(array( + 'name' => 'i18n_node_options_blog', + 'value' => 'a:2:{i:0;s:8:"required";i:1;s:4:"lock";}', +)) +->values(array( 'name' => 'language_count', 'value' => 'i:2;', ))