Commit d654e103 authored by catch's avatar catch

Issue #2975509 by quietone, masipila, gaydabura, jhodgdon, maxocub: Migrate D6...

Issue #2975509 by quietone, masipila, gaydabura, jhodgdon, maxocub: Migrate D6 vocabulary language settings
parent e172a37a
id: d6_language_content_taxonomy_vocabulary_settings
label: Drupal 6 language taxonomy vocabulary settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: d6_language_content_settings_taxonomy_vocabulary
constants:
target_type: 'taxonomy_term'
default_langcode: 'site_default'
process:
target_bundle:
-
plugin: migration_lookup
migration: d6_taxonomy_vocabulary
source: vid
-
plugin: skip_on_empty
method: row
# State is the value in the i18ntaxonomy_vocabulary array defined as:
# 0: No multilingual options.
# 1: Localizable terms. Run through the localization system.
# 2: Predefined language for a vocabulary and its terms.
# 3: Per-language terms, translatable (referencing terms with different
# languages) but not localizable.
language_alterable:
plugin: static_map
source: state
map:
0: false
1: true
2: false
3: true
'third_party_settings/content_translation/enabled':
plugin: static_map
source: state
map:
0: false
1: true
2: false
3: false
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:
- d6_taxonomy_vocabulary
<?php
namespace Drupal\language\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 i18n vocabularies source from database.
*
* @MigrateSource(
* id = "d6_language_content_settings_taxonomy_vocabulary",
* source_module = "taxonomy"
* )
*/
class LanguageContentSettingsTaxonomyVocabulary extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('vocabulary', 'v')
->fields('v', ['vid', 'language']);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'vid' => $this->t('The vocabulary ID.'),
'language' => $this->t('The default language for new terms.'),
'state' => $this->t('The i18n taxonomy translation setting.'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Get the i18n taxonomy translation setting for this vocabulary.
// 0 - No multilingual options
// 1 - Localizable terms. Run through the localization system.
// 2 - Predefined language for a vocabulary and its terms.
// 3 - Per-language terms, translatable (referencing terms with different
// languages) but not localizable.
$i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', NULL);
$vid = $row->getSourceProperty('vid');
$state = FALSE;
if (array_key_exists($vid, $i18ntaxonomy_vocabulary)) {
$state = $i18ntaxonomy_vocabulary[$vid];
}
$row->setSourceProperty('state', $state);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
return $ids;
}
}
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d6;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of i18ntaxonomy vocabulary settings.
*
* @group migrate_drupal_6
*/
class MigrateLanguageContentTaxonomyVocabularySettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'language',
'content_translation',
'taxonomy',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
$this->executeMigrations([
'language',
'd6_taxonomy_vocabulary',
'd6_language_content_taxonomy_vocabulary_settings',
]);
}
/**
* Tests migration of 18ntaxonomy vocabulary settings.
*/
public function testLanguageContentTaxonomy() {
$target_entity = 'taxonomy_term';
// Per Language.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_1_i_0_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => FALSE]);
// Set language to vocabulary.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_2_i_1_', 'fr', FALSE, ['enabled' => FALSE]);
// Localize terms.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_3_i_2_', LanguageInterface::LANGCODE_SITE_DEFAULT, TRUE, ['enabled' => TRUE]);
// None translation enabled.
$this->assertLanguageContentSettings($target_entity, 'vocabulary_name_much_longer_than', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'tags', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'forums', LanguageInterface::LANGCODE_SITE_DEFAULT, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'type', LanguageInterface::LANGCODE_SITE_DEFAULT, 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'));
}
}
<?php
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests i18ntaxonomy vocabulary setting source plugin.
*
* @covers \Drupal\language\Plugin\migrate\source\d6\LanguageContentSettingsTaxonomyVocabulary
*
* @group language
*/
class LanguageContentTaxonomyVocabularySettingsTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'language', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['vocabulary'] = [
[
'vid' => 1,
'name' => 'Tags',
'description' => 'Tags description.',
'help' => 1,
'relations' => 0,
'hierarchy' => 0,
'multiple' => 0,
'required' => 0,
'tags' => 1,
'module' => 'taxonomy',
'weight' => 0,
'language' => '',
],
[
'vid' => 2,
'name' => 'Categories',
'description' => 'Categories description.',
'help' => 1,
'relations' => 1,
'hierarchy' => 1,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'module' => 'taxonomy',
'weight' => 0,
'language' => 'zu',
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'i18ntaxonomy_vocabulary',
'value' => 'a:4:{i:1;s:1:"3";i:2;s:1:"2";i:3;s:1:"3";i:5;s:1:"1";}',
],
];
$tests[0]['expected_data'] = [
[
'vid' => 1,
'language' => '',
'state' => 3,
],
[
'vid' => 2,
'language' => 'zu',
'state' => 2,
],
];
return $tests;
}
}
......@@ -48491,7 +48491,7 @@
))
->values(array(
'name' => 'i18ntaxonomy_vocabulary',
'value' => 'a:2:{i:1;s:1:"3";i:2;s:1:"2";}',
'value' => 'a:3:{i:1;s:1:"3";i:2;s:1:"2";i:3;s:1:"1";}',
))
->values(array(
'name' => 'i18n_lock_node_article',
......@@ -72,7 +72,7 @@ protected function getEntityCounts() {
'file' => 7,
'filter_format' => 7,
'image_style' => 5,
'language_content_settings' => 3,
'language_content_settings' => 10,
'migration' => 105,
'node' => 18,
// The 'book' module provides the 'book' node type, and the migration
......
......@@ -51,6 +51,21 @@ process:
'settings/handler_settings/target_bundles/0': '@field_name'
'settings/handler_settings/auto_create': 'constants/auto_create'
required: required
# Get the i18n taxonomy translation setting for this vocabulary.
# 0 - No multilingual options
# 1 - Localizable terms. Run through the localization system.
# 2 - Predefined language for a vocabulary and its terms.
# 3 - Per-language terms, translatable (referencing terms with different
# languages) but not localizable.
translatable:
plugin: static_map
source: i18ntaxonomy_vocabulary
default_value: 0
map:
0: false
1: false
2: false
3: true
destination:
plugin: entity:field_config
migration_dependencies:
......
......@@ -2,6 +2,8 @@
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
/**
* Gets all the vocabularies based on the node types that have Taxonomy enabled.
*
......@@ -22,6 +24,26 @@ public function query() {
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Get the i18n taxonomy translation setting for this vocabulary.
// 0 - No multilingual options
// 1 - Localizable terms. Run through the localization system.
// 2 - Predefined language for a vocabulary and its terms.
// 3 - Per-language terms, translatable (referencing terms with different
// languages) but not localizable.
$i18ntaxonomy_vocab = $this->variableGet('i18ntaxonomy_vocabulary', NULL);
$vid = $row->getSourceProperty('vid');
$i18ntaxonomy_vocabulary = FALSE;
if (array_key_exists($vid, $i18ntaxonomy_vocab)) {
$i18ntaxonomy_vocabulary = $i18ntaxonomy_vocab[$vid];
}
$row->setSourceProperty('i18ntaxonomy_vocabulary', $i18ntaxonomy_vocabulary);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
......
......@@ -39,19 +39,21 @@ protected function setUp() {
public function testVocabularyFieldInstance() {
$this->executeMigration('d6_vocabulary_field_instance');
// Test that the field exists.
// Test that the field exists. Tags has a multilingual option of 'None'.
$field_id = 'node.article.field_tags';
$field = FieldConfig::load($field_id);
$this->assertSame($field_id, $field->id(), 'Field instance exists on article bundle.');
$this->assertSame('Tags', $field->label());
$this->assertTrue($field->isRequired(), 'Field is required');
$this->assertFalse($field->isTranslatable());
// Test the page bundle as well.
// Test the page bundle as well. Tags has a multilingual option of 'None'.
$field_id = 'node.page.field_tags';
$field = FieldConfig::load($field_id);
$this->assertSame($field_id, $field->id(), 'Field instance exists on page bundle.');
$this->assertSame('Tags', $field->label());
$this->assertTrue($field->isRequired(), 'Field is required');
$this->assertFalse($field->isTranslatable());
$settings = $field->getSettings();
$this->assertSame('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
......@@ -60,15 +62,32 @@ public function testVocabularyFieldInstance() {
$this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
// Test the the field vocabulary_1_i_0_.
// Test the the field vocabulary_1_i_0_ with multilingual option,
// 'per language terms'.
$field_id = 'node.story.field_vocabulary_1_i_0_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertTrue($field->isTranslatable());
// Test the the field vocabulary_2_i_0_ with multilingual option,
// 'Set language to vocabulary'.
$field_id = 'node.story.field_vocabulary_2_i_1_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertFalse($field->isTranslatable());
// Test the the field vocabulary_3_i_0_ with multilingual option,
// 'Localize terms'.
$field_id = 'node.story.field_vocabulary_3_i_2_';
$field = FieldConfig::load($field_id);
$this->assertFalse($field->isRequired(), 'Field is not required');
$this->assertFalse($field->isTranslatable());
// Tests that a vocabulary named like a D8 base field will be migrated and
// prefixed with 'field_' to avoid conflicts.
$field_type = FieldConfig::load('node.sponsor.field_type');
$this->assertInstanceOf(FieldConfig::class, $field_type);
$this->assertFalse($field->isTranslatable());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment