Skip to content
Snippets Groups Projects
Commit f773bf9c authored by catch's avatar catch
Browse files

Issue #2225271 by penyaskito, quietone, svendecabooter, benjy, vasi: Migrate...

Issue #2225271 by penyaskito, quietone, svendecabooter, benjy, vasi: Migrate content type language settings from Drupal 6 & 7
parent 87f6b355
No related branches found
No related tags found
No related merge requests found
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
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
<?php
namespace Drupal\language\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal multilingual node settings from database.
*
* @MigrateSource(
* id = "d6_language_content_settings",
* )
*/
class LanguageContentSettings extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->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;
}
}
<?php
namespace Drupal\language\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal multilingual node settings from database.
*
* @MigrateSource(
* id = "d7_language_content_settings",
* )
*/
class LanguageContentSettings extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->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;
}
}
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d6;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of language content setting variables,
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
*
* @group migrate_drupal_6
*/
class MigrateLanguageContentSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'text', 'language', 'content_translation'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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());
}
}
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d7;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of language content setting variables,
* language_content_type_$type, i18n_node_options_* and i18n_lock_node_*.
*
* @group migrate_drupal_7
*/
class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'text', 'language', 'content_translation'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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');
}
}
......@@ -45533,6 +45533,14 @@
'name' => 'language_content_type_article',
'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;',
......@@ -41322,6 +41322,10 @@
'name' => 'language_content_type_test_content_type',
'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;',
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment