diff --git a/core/modules/migrate/src/Plugin/migrate/destination/PerNodeTypeMultilingualSettings.php b/core/modules/migrate/src/Plugin/migrate/destination/PerNodeTypeMultilingualSettings.php new file mode 100644 index 0000000..c09e132 --- /dev/null +++ b/core/modules/migrate/src/Plugin/migrate/destination/PerNodeTypeMultilingualSettings.php @@ -0,0 +1,55 @@ + $this->t('Node type'), + 'langcode' => $this->t('Langcode'), + 'language_show' => $this->t('Show language selector.'), + ); + } + + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = array()) { + $node_type = $row->getDestinationProperty('node_type'); + + $config = \Drupal::config('language.settings'); + $config->set("entities.node.$node_type.language.default_configuration.langcode", $row->getDestinationProperty('langcode')); + $config->set("entities.node.$node_type.language.default_configuration.language_show", $row->getDestinationProperty('language_show')); + $config->save(); + + return true; + } + +} diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_multilingual_node_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_multilingual_node_settings.yml new file mode 100644 index 0000000..49d94d4 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_multilingual_node_settings.yml @@ -0,0 +1,34 @@ +id: d6_multilingual_node_settings +label: Drupal 6 multilingual settings +migration_groups: + - Drupal 6 + - Drupal 6 Multilingual +source: + plugin: d6_multilingual_node_settings + constants: + langcode: 'current_interface' + language_show: true +process: + node_type: type + langcode: + - + plugin: static_map + source: language_content_type + map: + 0: NULL + 1: 'current_interface' + 2: 'current_interface' + - + plugin: skip_row_on_empty + language_show: + plugin: static_map + source: language_content_type + map: + 0: NULL + 1: true + 2: true +destination: + plugin: node_type_multilingual_settings +migration_dependencies: + required: + - d6_node_type diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/MultilingualNodeSettings.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/MultilingualNodeSettings.php new file mode 100644 index 0000000..16f13f1 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/MultilingualNodeSettings.php @@ -0,0 +1,88 @@ +select('node_type', 't') + ->fields('t', array( + 'type', + )) + ->orderBy('t.type'); + } + + /** + * {@inheritdoc} + */ + public function count() { + return count($this->runQuery()); + } + + /** + * {@inheritdoc} + */ + public function runQuery() { + $types = array(); + $iterator = $this->query()->execute(); + + foreach ($iterator as $type) { + $typeMachineName = $type['type']; + $types[$typeMachineName] = $type; + $types[$typeMachineName]['language_content_type'] = $this->variableGet('language_content_type_' . $typeMachineName, NULL); + $types[$typeMachineName]['i18n_newnode_current'] = $this->variableGet('i18n_newnode_current_' . $typeMachineName, NULL); + $types[$typeMachineName]['i18n_required_node'] = $this->variableGet('i18n_required_node_' . $typeMachineName, NULL); + $types[$typeMachineName]['i18n_lock_node'] = $this->variableGet('i18n_lock_node_' . $typeMachineName, NULL); + $types[$typeMachineName]['i18n_node'] = $this->variableGet('i18n_node_' . $typeMachineName, NULL); + } + return new \ArrayIterator($types); + } + + public function fields() { + $fields = array( + 'type' => $this->t('Type'), + 'language_content_type' => $this->t('Multilingual support'), + 'i18n_newnode_current' => $this->t('Set current language as default for new content.'), + // We ignore the required flag, as it is not possible to implement with + // Drupal 8 core. + 'i18n_required_node' => $this->t('Require language (Do not allow Language Neutral).'), + // We ignore the locked flag, as it is not possible to implement with + // Drupal 8 core. + 'i18n_lock_node' => $this->t('Lock language (Cannot be changed).'), + // If enabled, all defined languages will be allowed for this content type + // in addition to only enabled ones. This is useful to have more languages + // for content than for the interface. + // We ignore this setting as it is not possible to implement similar + // feature with Drupal 8. + 'i18n_node' => $this->t('Extended language support'), + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['type']['type'] = 'string'; + $ids['type']['alias'] = 't'; + return $ids; + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6MultilingualNodeSettings.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6MultilingualNodeSettings.php new file mode 100644 index 0000000..43f96da --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6MultilingualNodeSettings.php @@ -0,0 +1,40 @@ +createTable('variable'); + $this->database->insert('variable')->fields(array( + 'name', + 'value', + )) + ->values(array( + 'name' => 'language_content_type_test_event', + 'value' => 's:1:"0";', + )) + ->values(array( + 'name' => 'language_content_type_test_page', + 'value' => 's:1:"1";', + )) + ->values(array( + 'name' => 'language_content_type_test_story', + 'value' => 's:1:"2";', + )) + ->execute(); + + // We need a 6005 or greater db version; variables got renamed. + $this->setModuleVersion('locale', '6005'); + + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateMultilingualNodeSettingsTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateMultilingualNodeSettingsTest.php new file mode 100644 index 0000000..562c854 --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateMultilingualNodeSettingsTest.php @@ -0,0 +1,77 @@ + 'test_page'))->save(); + entity_create('node_type', array('type' => 'test_story'))->save(); + entity_create('node_type', array('type' => 'test_event'))->save(); + + $id_mappings = array( + 'd6_node_type' => array( + array(array('test_event'), array('test_event')), + array(array('test_page'), array('test_page')), + array(array('test_story'), array('test_story')), + ), + ); + $this->prepareMigrations($id_mappings); + + $migration = entity_load('migration', 'd6_multilingual_node_settings'); + $dumps = array( + $this->getDumpDirectory() . '/Drupal6NodeType.php', + $this->getDumpDirectory() . '/Drupal6MultilingualNodeSettings.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + /** + * Tests Drupal 6 multilingual node settings to Drupal 8 migration. + */ + public function testMultilingualNodeSettings() { + $config = \Drupal::config('language.settings'); + + $this->assertIdentical($config->get('entities.node.test_event'), NULL); + + $this->assertIdentical($config->get('entities.node.test_page.language.default_configuration.langcode'), 'current_interface'); + $this->assertIdentical($config->get('entities.node.test_page.language.default_configuration.language_show'), true); + + $this->assertIdentical($config->get('entities.node.test_story.language.default_configuration.langcode'), 'current_interface'); + $this->assertIdentical($config->get('entities.node.test_story.language.default_configuration.language_show'), true); + // $this->assertConfigSchema(\Drupal::service('config.typed'), 'language.settings', $config->get()); + } +} + diff --git a/core/modules/migrate_drupal/tests/src/source/d6/MultilingualNodeSettingsTest.php b/core/modules/migrate_drupal/tests/src/source/d6/MultilingualNodeSettingsTest.php new file mode 100644 index 0000000..fd01bde --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/source/d6/MultilingualNodeSettingsTest.php @@ -0,0 +1,66 @@ + 'test', + 'idlist' => array(), + 'source' => array( + 'type' => 'page', + 'plugin' => 'd6_multilingual_node_settings', + ), + ); + + protected $expectedResults = array( + array( + 'type' => 'article', + ), + array( + 'type' => 'page', + ), + ); + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['node_type']['article'] = array('type' => 'article'); + $this->databaseContents['node_type']['page'] = array('type' => 'page'); + + parent::setUp(); + } + +} + +use Drupal\Core\Database\Connection; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\migrate_drupal\Plugin\migrate\source\d6\MultilingualNodeSettings; + +class TestMultilingualNodeSettings extends MultilingualNodeSettings { + public function setDatabase(Connection $database) { + $this->database = $database; + } + public function setModuleHandler(ModuleHandlerInterface $module_handler) { + $this->moduleHandler = $module_handler; + } +}