Commit d0114235 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3110669 by quietone, ravi.shankar: Migrate d7 menu language content settings

parent 97bac4f1
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
......@@ -8,6 +8,9 @@ finished:
taxonomy: language
7:
i18n_taxonomy: language
i18n_menu:
- language
locale:
- language
- system
system: language
<?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;
}
}
<?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}
*/
public static $modules = [
'content_translation',
'language',
'menu_link_content',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
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'));
}
}
<?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}
*/
public 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;
}
}
......@@ -79,7 +79,7 @@ protected function getEntityCounts() {
'file' => 3,
'filter_format' => 7,
'image_style' => 6,
'language_content_settings' => 18,
'language_content_settings' => 24,
'node' => 6,
'node_type' => 6,
'rdf_mapping' => 8,
......@@ -87,7 +87,7 @@ protected function getEntityCounts() {
'shortcut' => 6,
'shortcut_set' => 2,
'action' => 19,
'menu' => 6,
'menu' => 7,
'taxonomy_term' => 24,
'taxonomy_vocabulary' => 7,
'path_alias' => 8,
......@@ -186,6 +186,7 @@ protected function getMissingPaths() {
'i18n',
'i18n_field',
'i18n_string',
'i18n_menu',
'i18n_taxonomy',
'i18n_translation',
'locale',
......
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