Issue #3110669 by quietone, ravi.shankar, Gábor Hojtsy, xjm: Migrate d7 menu language content settings

merge-requests/2419/head
catch 2020-05-22 14:21:33 +01:00
parent 0aa8da919c
commit 6e78799528
7 changed files with 67 additions and 1097 deletions

View File

@ -1,53 +0,0 @@
id: d7_language_content_menu_settings
label: Drupal 7 language content menu settings
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_language_content_settings_menu
constants:
target_type: 'menu_link_content'
langcode: 'site_default'
process:
target_bundle:
-
plugin: migration_lookup
migration: d7_menu
source: menu_name
-
plugin: skip_on_empty
method: row
# State is the value in the i18n_mode column of menu_custom table
# 0: No multilingual options.
# 1: Localize. Localizable object. Run through the localization system
# 2: Fixed Language. Predefined language for this object and all related ones
# 4: Translate. Multilingual objects, translatable but not localizable.
# 5: Objects are translatable (if they have language or localizable if not)
language_alterable:
plugin: static_map
source: i18n_mode
map:
0: false
1: true
2: false
4: true
5: true
'third_party_settings/content_translation/enabled':
plugin: static_map
source: i18n_mode
map:
0: false
1: true
2: false
4: false
5: true
target_entity_type_id: 'constants/target_type'
default_langcode:
plugin: default_value
default_value: site_default
source: language
destination:
plugin: entity:language_content_settings
migration_dependencies:
required:
- d7_menu

View File

@ -8,9 +8,6 @@ finished:
taxonomy: language taxonomy: language
7: 7:
i18n_taxonomy: language i18n_taxonomy: language
i18n_menu:
- language
locale: locale:
- language - language
- system - system
system: language

View File

@ -1,50 +0,0 @@
<?php
namespace Drupal\language\Plugin\migrate\source\d7;
use Drupal\system\Plugin\migrate\source\Menu;
/**
* Drupal 7 i18n menu links source from database.
*
* @MigrateSource(
* id = "d7_language_content_settings_menu",
* source_module = "i18n_menu"
* )
*/
class LanguageContentSettingsMenu extends Menu {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
if ($this->getDatabase()
->schema()
->fieldExists('menu_custom', 'i18n_mode')) {
$query->addField('m', 'language');
$query->addField('m', 'i18n_mode');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = parent::fields();
$fields['language'] = $this->t('i18n language');
$fields['i18n_mode'] = $this->t('i18n mode');
return $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids = parent::getIds();
$ids['language']['type'] = 'string';
return $ids;
}
}

View File

@ -1,77 +0,0 @@
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d7;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of i18n_menu settings.
*
* @group migrate_drupal_7
*/
class MigrateLanguageContentMenuSettingsTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'content_translation',
'language',
'menu_link_content',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->executeMigrations([
'language',
'd7_menu',
'd7_language_content_menu_settings',
]);
}
/**
* Tests migration of menu translation ability.
*/
public function testLanguageContentMenu() {
$target_entity = 'menu_link_content';
// No multilingual options, i18n_mode = 0.
$this->assertLanguageContentSettings($target_entity, 'main', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'admin', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'tools', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]);
$this->assertLanguageContentSettings($target_entity, 'account', LanguageInterface::LANGCODE_NOT_SPECIFIED, FALSE, ['enabled' => FALSE]);
// Translate and localize, i18n_mode = 5.
$this->assertLanguageContentSettings($target_entity, 'menu-test-menu', LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE, ['enabled' => TRUE]);
// Fixed language, i18n_mode = 2.
$this->assertLanguageContentSettings($target_entity, 'menu-fixedlang', 'is', 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'));
}
}

View File

@ -1,46 +0,0 @@
<?php
namespace Drupal\Tests\language\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\system\Kernel\Plugin\migrate\source\MenuTest;
/**
* Tests i18n menu links source plugin.
*
* @covers \Drupal\language\Plugin\migrate\source\d7\LanguageContentSettingsMenu
*
* @group language
*/
class LanguageContentMenuSettingsTest extends MenuTest {
/**
* {@inheritdoc}
*/
protected static $modules = [
'menu_link_content',
'language',
'migrate_drupal',
];
/**
* {@inheritdoc}
*/
public function providerSource() {
// Get the source data from parent.
$tests = parent::providerSource();
foreach ($tests as &$test) {
// Add the extra columns provided by i18n_menu.
foreach ($test['source_data']['menu_custom'] as &$vocabulary) {
$vocabulary['language'] = 'und';
$vocabulary['i18n_mode'] = 2;
}
foreach ($test['expected_data'] as &$expected) {
$expected['language'] = 'und';
$expected['i18n_mode'] = 2;
}
}
return $tests;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,7 @@ class Upgrade7Test extends MigrateUpgradeExecuteTestBase {
'file' => 3, 'file' => 3,
'filter_format' => 7, 'filter_format' => 7,
'image_style' => 6, 'image_style' => 6,
'language_content_settings' => 26, 'language_content_settings' => 20,
'node' => 7, 'node' => 7,
'node_type' => 7, 'node_type' => 7,
'rdf_mapping' => 8, 'rdf_mapping' => 8,
@ -100,7 +100,7 @@ class Upgrade7Test extends MigrateUpgradeExecuteTestBase {
'shortcut' => 6, 'shortcut' => 6,
'shortcut_set' => 2, 'shortcut_set' => 2,
'action' => 19, 'action' => 19,
'menu' => 7, 'menu' => 6,
'taxonomy_term' => 24, 'taxonomy_term' => 24,
'taxonomy_vocabulary' => 7, 'taxonomy_vocabulary' => 7,
'path_alias' => 8, 'path_alias' => 8,
@ -200,7 +200,6 @@ class Upgrade7Test extends MigrateUpgradeExecuteTestBase {
'Field translation', 'Field translation',
'Internationalization', 'Internationalization',
'Locale', 'Locale',
'Menu translation',
'String translation', 'String translation',
'Taxonomy translation', 'Taxonomy translation',
'Translation sets', 'Translation sets',