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..4d094a5 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_multilingual_node_settings.yml @@ -0,0 +1,20 @@ +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: + 'entities/node/article/language/default_configuration': + - langcode: 'constants/langcode' + - language_show: 'constants/languageshow' +destination: + plugin: config + config_name: language.settings +migration_dependencies: + required: + - d6_node_types 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..f065a21 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/MultilingualNodeSettings.php @@ -0,0 +1,85 @@ +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 = parent::runQuery(); + + 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); + } + fwrite(STDERR, print_r("penyaskito", TRUE)); + fwrite(STDERR, print_r($types, TRUE)); + 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.'), + 'i18n_required_node' => $this->t('Require language (Do not allow Language Neutral).'), // we ignore this one (not possible in d8) + 'i18n_lock_node' => $this->t('Lock language (Cannot be changed).'), // we ignore this one (not possible in d8) + // 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. + 'i18n_node' => $this->t('Extended language support'), // we ignore this one (not possible in d8) + ); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + // $this->configuration['bundle'] + $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..dc2e9b5 --- /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_page', + 'value' => 's:1:"1";', + )) + ->values(array( + 'name' => 'language_content_type_article', + 'value' => 's:1:"0";', + )) + ->values(array( + 'name' => 'language_content_type_report', + '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..187de6e --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateMultilingualNodeSettingsTest.php @@ -0,0 +1,70 @@ + 'article'))->save(); + entity_create('node_type', array('type' => 'page'))->save(); + entity_create('node_type', array('type' => 'event'))->save(); + + $id_mappings = array( + 'd6_node_type' => array( + array(array('article'), array('article')), + array(array('page'), array('page')), + array(array('event'), array('event')), + ), + ); + $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.article.language.default_configuration.langcode'), 'current_interface'); + $this->assertIdentical($config->get('entities.node.article.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; + } +}