Unverified Commit b61e2a65 authored by alexpott's avatar alexpott

Revert "Issue #2225587 by quietone, Jo Fitzgerald, heddn, Pavan B S, maxocub,...

Revert "Issue #2225587 by quietone, Jo Fitzgerald, heddn, Pavan B S, maxocub, phenaproxima, Gábor Hojtsy, ao2, alexpott: Migrate D6 i18n menu links"

This reverts commit 66480d7f.
parent d25a77e0
id: d6_language_content_menu_settings
label: Drupal 6 language content menu settings
migration_tags:
- Drupal 6
- Configuration
source:
plugin: extension
name: i18nmenu
constants:
target_type: 'menu_link_content'
langcode: 'site_default'
process:
target_entity_type_id: 'constants/target_type'
# menu_link_content has a bundle key but no bundle support so use the entity
# type as the bundle.
target_bundle: 'constants/target_type'
default_langcode: 'constants/langcode'
# Drupal 6 menus are translated when the i18nmenu module is enabled.
language_alterable: status
destination:
plugin: entity:language_content_settings
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d6;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of the ability to translate menu content.
*
* @group migrate_drupal_6
*/
class MigrateLanguageContentMenuSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'language',
'content_translation',
'menu_link_content',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some languages.
ConfigurableLanguage::createFromLangcode('en')->save();
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->executeMigrations(['d6_language_content_menu_settings']);
}
/**
* Tests migration of menu translation ability.
*/
public function testLanguageMenuContent() {
$config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
$this->assertInstanceOf(ContentLanguageSettings::class, $config);
$this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
$this->assertSame('menu_link_content', $config->getTargetBundle());
$this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
// Test that menus are not alterable when the i18nmenu is not enabled.
$this->sourceDatabase->update('system')
->fields(['status' => 0])
->condition('name', 'i18nmenu')
->execute();
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d6_language_content_menu_settings');
// Indicate we're rerunning a migration that's already run.
$migration->getIdMap()->prepareUpdate();
$this->executeMigration($migration);
$config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
$this->assertInstanceOf(ContentLanguageSettings::class, $config);
$this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
$this->assertSame('menu_link_content', $config->getTargetBundle());
$this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
$this->assertFalse($config->isLanguageAlterable());
}
}
id: d6_menu_links_translation
label: Menu links
migration_tags:
- Drupal 6
- Content
source:
plugin: d6_menu_link_translation
process:
id: mlid
langcode: language
title:
-
plugin: callback
source:
- title_translated
- link_title
callable: array_filter
-
plugin: callback
callable: current
description:
-
plugin: callback
source:
- description_translated
- description
callable: array_filter
-
plugin: callback
callable: current
menu_name:
-
plugin: migration_lookup
# The menu migration is in the system module.
migration: d6_menu
source: menu_name
-
plugin: skip_on_empty
method: row
-
plugin: static_map
map:
management: admin
bypass: true
destination:
plugin: entity:menu_link_content
default_bundle: menu_link_content
no_stub: true
translations: true
migration_dependencies:
required:
- language
- d6_menu
- d6_menu_links
<?php
namespace Drupal\menu_link_content\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\menu_link_content\Plugin\migrate\source\MenuLink;
/**
* Gets Menu link translations from source database.
*
* @MigrateSource(
* id = "d6_menu_link_translation",
* source_module = "i18nmenu"
* )
*/
class MenuLinkTranslation extends MenuLink {
/**
* {@inheritdoc}
*/
public function query() {
// Ideally, the query would return rows for each language for each menu link
// with the translations for both the title and description or just the
// title translation or just the description translation. That query quickly
// became complex and would be difficult to maintain.
// Therefore, build a query based on i18nstrings table where each row has
// the translation for only one property, either title or description. The
// method prepareRow() is then used to obtain the translation for the other
// property.
// The query starts with the same query as menu_link.
$query = parent::query();
// Add in the property, which is either title or description.
$query->leftJoin('i18n_strings', 'i18n', 'ml.mlid = i18n.objectid');
$query->isNotNull('i18n.lid');
$query->addField('i18n', 'lid');
$query->addField('i18n', 'property');
// Add in the translation for the property.
$query->innerJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
$query->addField('lt', 'language');
$query->addField('lt', 'translation');
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$language = $row->getSourceProperty('language');
$mlid = $row->getSourceProperty('mlid');
// If this row has been migrated it is a duplicate then skip it.
if ($this->idMap->lookupDestinationIds(['mlid' => $mlid, 'language' => $language])) {
return FALSE;
}
// Save the translation for this property.
$property = $row->getSourceProperty('property');
$row->setSourceProperty($property . '_translated', $row->getSourceProperty('translation'));
// Get the translation, if one exists, for the property not already in the
// row.
$other_property = ($property == 'title') ? 'description' : 'title';
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n', ['lid'])
->condition('i18n.property', $other_property)
->condition('i18n.objectid', $mlid);
$query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
$query->condition('lt.language', $language);
$query->addField('lt', 'translation');
$results = $query->execute()->fetchAssoc();
$row->setSourceProperty($other_property . '_translated', $results['translation']);
parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'language' => $this->t('Language for this menu.'),
'title_translated' => $this->t('Menu link title translation.'),
'description_translated' => $this->t('Menu link description translation.'),
];
return parent::fields() + $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['language']['type'] = 'string';
return parent::getIds() + $ids;
}
}
......@@ -84,7 +84,7 @@ protected function assertEntity($id, $title, $menu, $description, $enabled, $exp
* Tests migration of menu links.
*/
public function testMenuLinks() {
$this->assertEntity('138', 'Test 1', 'secondary-links', 'Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'Test menu link 1'], 'langcode' => 'en'], 'internal:/user/login', -50);
$this->assertEntity('138', 'Test 1', 'secondary-links', 'Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'Test menu link 1']], 'internal:/user/login', -50);
$this->assertEntity('139', 'Test 2', 'secondary-links', 'Test menu link 2', TRUE, TRUE, ['query' => 'foo=bar', 'attributes' => ['title' => 'Test menu link 2']], 'internal:/admin', -49);
$this->assertEntity('140', 'Drupal.org', 'secondary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => '']], 'https://www.drupal.org', -50);
......@@ -96,9 +96,6 @@ public function testMenuLinks() {
$this->assertEntity('460', 'Le Vrai McCoy', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/10', 0);
$this->assertEntity('461', 'Abantu zulu', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/12', 0);
$this->assertEntity('462', 'The Zulu People', 'primary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => ''], 'alter' => TRUE], 'entity:node/12', 0);
// Test the migration of menu links translation.
$this->assertEntity('463', 'fr - Test 1', 'secondary-links', 'fr - Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'fr - Test menu link 1'], 'langcode' => 'fr', 'alter' => TRUE], 'internal:/user/login', -49);
}
}
<?php
namespace Drupal\Tests\menu_link_content\Kernel\Migrate\d6;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Menu link migration.
*
* @group migrate_drupal_6
*/
class MigrateMenuLinkTranslationTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_ui', 'menu_link_content', 'language'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migrateContent();
$this->installSchema('system', ['router']);
$this->installEntitySchema('menu_link_content');
$this->executeMigrations([
'language',
'd6_menu',
'd6_menu_links',
'd6_menu_links_translation',
]);
}
/**
* Tests migration of menu links.
*/
public function testMenuLinks() {
/** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
$menu_link = MenuLinkContent::load(139)->getTranslation('fr');
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertSame('fr - Test 2', $menu_link->getTitle());
$this->assertSame('fr - Test menu link 2', $menu_link->getDescription());
$this->assertSame('secondary-links', $menu_link->getMenuName());
$this->assertTrue($menu_link->isEnabled());
$this->assertTrue($menu_link->isExpanded());
$this->assertSame(['query' => 'foo=bar', 'attributes' => ['title' => 'Test menu link 2']], $menu_link->link->options);
$this->assertSame('internal:/admin', $menu_link->link->uri);
$this->assertSame(-49, $menu_link->getWeight());
$menu_link = MenuLinkContent::load(139)->getTranslation('zu');
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertSame('Test 2', $menu_link->getTitle());
$this->assertSame('zu - Test menu link 2', $menu_link->getDescription());
$this->assertSame('secondary-links', $menu_link->getMenuName());
$this->assertTrue($menu_link->isEnabled());
$this->assertTrue($menu_link->isExpanded());
$this->assertSame(['query' => 'foo=bar', 'attributes' => ['title' => 'Test menu link 2']], $menu_link->link->options);
$this->assertSame('internal:/admin', $menu_link->link->uri);
$this->assertSame(-49, $menu_link->getWeight());
$menu_link = MenuLinkContent::load(140)->getTranslation('fr');
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertSame('fr - Drupal.org', $menu_link->getTitle());
$this->assertSame('', $menu_link->getDescription());
$this->assertSame('secondary-links', $menu_link->getMenuName());
$this->assertTrue($menu_link->isEnabled());
$this->assertFalse($menu_link->isExpanded());
$this->assertSame(['attributes' => ['title' => '']], $menu_link->link->options);
$this->assertSame('https://www.drupal.org', $menu_link->link->uri);
$this->assertSame(-50, $menu_link->getWeight());
$menu_link = MenuLinkContent::load(463);
$this->assertInstanceOf(MenuLinkContent::class, $menu_link);
$this->assertSame('fr - Test 1', $menu_link->getTitle());
$this->assertSame('fr - Test menu link 1', $menu_link->getDescription());
$this->assertSame('secondary-links', $menu_link->getMenuName());
$this->assertTrue($menu_link->isEnabled());
$this->assertFalse($menu_link->isExpanded());
$attributes = [
'attributes' => [
'title' => 'fr - Test menu link 1',
],
'langcode' => 'fr',
'alter' => TRUE,
];
$this->assertSame($attributes, $menu_link->link->options);
$this->assertSame('internal:/user/login', $menu_link->link->uri);
$this->assertSame(-49, $menu_link->getWeight());
}
}
<?php
namespace Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests menu link translation source plugin.
*
* @covers \Drupal\menu_link_content\Plugin\migrate\source\d6\MenuLinkTranslation
* @group menu_link_content
*/
class MenuLinkTranslationTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_link_content', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$test = [];
$test[0]['source_data']['menu_links'] = [
[
'menu_name' => 'menu-test-menu',
'mlid' => 138,
'plid' => 0,
'link_path' => 'admin',
'router_path' => 'admin',
'link_title' => 'Test 1',
'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 1";}}',
'module' => 'menu',
'hidden' => 0,
'external' => 0,
'has_children' => 1,
'expanded' => 0,
'weight' => 15,
'depth' => 1,
'customized' => 1,
'p1' => '138',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 139,
'plid' => 138,
'link_path' => 'admin/modules',
'router_path' => 'admin/modules',
'link_title' => 'Test 2',
'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 2";}}',
'module' => 'menu',
'hidden' => 0,
'external' => 0,
'has_children' => 0,
'expanded' => 0,
'weight' => 12,
'depth' => 2,
'customized' => 1,
'p1' => '138',
'p2' => '139',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 140,
'plid' => 0,
'link_path' => 'https://www.drupal.org',
'router_path' => 'admin/modules',
'link_title' => 'Test 2',
'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 2";}}',
'module' => 'menu',
'hidden' => 0,
'external' => 0,
'has_children' => 0,
'expanded' => 0,
'weight' => 12,
'depth' => 2,
'customized' => 1,
'p1' => '0',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 141,
'plid' => 0,
'link_path' => 'https://api.drupal.org/api/drupal/8.3.x',
'router_path' => 'admin/modules',
'link_title' => 'Test 3',
'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 3";}}',
'module' => 'menu',
'hidden' => 0,
'external' => 0,
'has_children' => 0,
'expanded' => 0,
'weight' => 12,
'depth' => 2,
'customized' => 1,
'p1' => '0',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
],
];
$test[0]['source_data']['i18n_strings'] = [
[
'lid' => 1,
'objectid' => 139,
'type' => 'item',
'property' => 'title',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 2,
'objectid' => 139,
'type' => 'item',
'property' => 'description',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 3,
'objectid' => 140,
'type' => 'item',
'property' => 'description',
'objectindex' => 0,
'format' => 0,
],
[
'lid' => 4,
'objectid' => 141,
'type' => 'item',
'property' => 'title',
'objectindex' => 0,
'format' => 0,
],
];
$test[0]['source_data']['locales_target'] = [
[
'lid' => 1,
'language' => 'fr',
'translation' => 'fr - title translation',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 2,
'language' => 'fr',
'translation' => 'fr - description translation',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 3,
'language' => 'zu',
'translation' => 'zu - description translation',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
[
'lid' => 4,
'language' => 'zu',
'translation' => 'zu - title translation',
'plid' => 0,
'plural' => 0,
'i18n_status' => 0,
],
];
$test[0]['expected_results'] = [
[
'menu_name' => 'menu-test-menu',
'mlid' => 139,
'property' => 'title',
'language' => 'fr',
'link_title' => 'Test 2',
'description' => 'Test menu link 2',
'title_translated' => 'fr - title translation',
'description_translated' => 'fr - description translation',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 139,
'property' => 'description',
'language' => 'fr',
'link_title' => 'Test 2',
'description' => 'Test menu link 2',
'title_translated' => 'fr - title translation',
'description_translated' => 'fr - description translation',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 140,
'property' => 'description',
'language' => 'zu',
'link_title' => 'Test 2',
'description' => 'Test menu link 2',
'title_translated' => NULL,
'description_translated' => 'zu - description translation',
],
[
'menu_name' => 'menu-test-menu',
'mlid' => 141,
'property' => 'title',
'language' => 'zu',
'link_title' => 'Test 3',
'description' => 'Test menu link 3',
'title_translated' => 'zu - title translation',
'description_translated' => NULL,
],
];
return $test;
}
}
......@@ -563,13 +563,9 @@ public function lookupDestinationIds(array $source_id_values) {
$conditions = [];
foreach ($this->sourceIdFields() as $field_name => $db_field) {
if ($is_associative) {
// Ensure to handle array elements with a NULL value.
if (array_key_exists($field_name, $source_id_values)) {
// Associative $source_id_values can have fields out of order.
if (isset($source_id_values[$field_name])) {
// Only add a condition if the value is not NULL.
$conditions[$db_field] = $source_id_values[$field_name];
}
// Associative $source_id_values can have fields out of order.
if (isset($source_id_values[$field_name])) {
$conditions[$db_field] = $source_id_values[$field_name];
unset($source_id_values[$field_name]);
}
}
......@@ -584,8 +580,7 @@ public function lookupDestinationIds(array $source_id_values) {
}
if (!empty($source_id_values)) {
$var_dump = var_export($source_id_values, TRUE);
throw new MigrateException(sprintf("Extra unknown items in source IDs: %s", $var_dump));
throw new MigrateException("Extra unknown items in source IDs");
}
$query = $this->getDatabase()->select($this->mapTableName(), 'map')
......
......@@ -517,8 +517,6 @@ public function testLookupDestinationIds() {
$this->assertEquals([[101, 'en'], [101, 'fr'], [101, 'de']], $id_map->lookupDestinationIds(['nid' => 1]));
$this->assertEquals([[102, 'en']], $id_map->lookupDestinationIds(['nid' => 2]));
$this->assertEquals([], $id_map->lookupDestinationIds(['nid' => 99]));
$this->assertEquals([[101, 'en'], [101, 'fr'], [101, 'de']], $id_map->lookupDestinationIds(['nid' => 1, 'language' => NULL]));
$this->assertEquals([[102, 'en']], $id_map->lookupDestinationIds(['nid' => 2, 'language' => NULL]));
// Out-of-order partial associative list.
$this->assertEquals([[101, 'en'], [102, 'en']], $id_map->lookupDestinationIds(['language' => 'en']));
$this->assertEquals([[101, 'fr']], $id_map->lookupDestinationIds(['language' => 'fr']));
......@@ -529,14 +527,14 @@ public function testLookupDestinationIds() {
$this->fail('Too many source IDs should throw');
}
catch (MigrateException $e) {
$this->assertEquals("Extra unknown items in source IDs: array (\n 0 => 3,\n)", $e->getMessage());
$this->assertEquals("Extra unknown items in source IDs", $e->getMessage());
}
try {
$id_map->lookupDestinationIds(['nid' => 1, 'aaa' => '2']);
$this->fail('Unknown source ID key should throw');
}
catch (MigrateException $e) {
$this->assertEquals("Extra unknown items in source IDs: array (\n 'aaa' => '2',\n)", $e->getMessage());
$this->assertEquals("Extra unknown items in source IDs", $e->getMessage());
}
// Verify that we are looking up by source_id_hash when all source IDs are
......
......@@ -9710,38 +9710,6 @@
'objectindex' => '7',
'format' => '0',
))
->values(array(
'lid' => '1674',