From 66480d7f4034b0a048bf03b36af515076a15589d Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 10 Apr 2018 11:25:55 +0100
Subject: [PATCH] =?UTF-8?q?Issue=20#2225587=20by=20quietone,=20Jo=20Fitzge?=
 =?UTF-8?q?rald,=20heddn,=20Pavan=20B=20S,=20maxocub,=20phenaproxima,=20G?=
 =?UTF-8?q?=C3=A1bor=20Hojtsy,=20ao2,=20alexpott:=20Migrate=20D6=20i18n=20?=
 =?UTF-8?q?menu=20links?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../d6_language_content_menu_settings.yml     |  21 ++
 ...MigrateLanguageContentMenuSettingsTest.php |  68 +++++
 .../migrations/d6_menu_links_translation.yml  |  54 ++++
 .../migrate/source/d6/MenuLinkTranslation.php |  97 +++++++
 .../Kernel/Migrate/d6/MigrateMenuLinkTest.php |   5 +-
 .../d6/MigrateMenuLinkTranslationTest.php     |  93 +++++++
 .../source/d6/MenuLinkTranslationTest.php     | 250 ++++++++++++++++++
 .../migrate/src/Plugin/migrate/id_map/Sql.php |  13 +-
 .../tests/src/Unit/MigrateSqlIdMapTest.php    |   6 +-
 .../migrate_drupal/tests/fixtures/drupal6.php |  89 ++++++-
 .../d6/MigrateUpgrade6ReviewPageTest.php      |   2 +-
 .../src/Functional/d6/MigrateUpgrade6Test.php |   8 +-
 .../src/Plugin/migrate/source/Extension.php   |  66 +++++
 .../Plugin/migrate/source/ExtensionTest.php   |  77 ++++++
 14 files changed, 836 insertions(+), 13 deletions(-)
 create mode 100644 core/modules/language/migrations/d6_language_content_menu_settings.yml
 create mode 100644 core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentMenuSettingsTest.php
 create mode 100644 core/modules/menu_link_content/migrations/d6_menu_links_translation.yml
 create mode 100644 core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php
 create mode 100644 core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTranslationTest.php
 create mode 100644 core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/MenuLinkTranslationTest.php
 create mode 100644 core/modules/system/src/Plugin/migrate/source/Extension.php
 create mode 100644 core/modules/system/tests/src/Kernel/Plugin/migrate/source/ExtensionTest.php

diff --git a/core/modules/language/migrations/d6_language_content_menu_settings.yml b/core/modules/language/migrations/d6_language_content_menu_settings.yml
new file mode 100644
index 000000000000..8e015f21829d
--- /dev/null
+++ b/core/modules/language/migrations/d6_language_content_menu_settings.yml
@@ -0,0 +1,21 @@
+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
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentMenuSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentMenuSettingsTest.php
new file mode 100644
index 000000000000..0148452dc977
--- /dev/null
+++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentMenuSettingsTest.php
@@ -0,0 +1,68 @@
+<?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());
+  }
+
+}
diff --git a/core/modules/menu_link_content/migrations/d6_menu_links_translation.yml b/core/modules/menu_link_content/migrations/d6_menu_links_translation.yml
new file mode 100644
index 000000000000..71e55992e8af
--- /dev/null
+++ b/core/modules/menu_link_content/migrations/d6_menu_links_translation.yml
@@ -0,0 +1,54 @@
+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
diff --git a/core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php b/core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php
new file mode 100644
index 000000000000..dbc455b35321
--- /dev/null
+++ b/core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php
@@ -0,0 +1,97 @@
+<?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;
+  }
+
+}
diff --git a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php
index 7c7b57fbabbc..36e4f30dc0ae 100644
--- a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php
+++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTest.php
@@ -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']], 'internal:/user/login', -50);
+    $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('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,6 +96,9 @@ 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);
   }
 
 }
diff --git a/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTranslationTest.php b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTranslationTest.php
new file mode 100644
index 000000000000..21911f06f419
--- /dev/null
+++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTranslationTest.php
@@ -0,0 +1,93 @@
+<?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());
+  }
+
+}
diff --git a/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/MenuLinkTranslationTest.php b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/MenuLinkTranslationTest.php
new file mode 100644
index 000000000000..d373bb25873c
--- /dev/null
+++ b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/MenuLinkTranslationTest.php
@@ -0,0 +1,250 @@
+<?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;
+  }
+
+}
diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
index a69e31cba9d5..946b208a101a 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -563,9 +563,13 @@ public function lookupDestinationIds(array $source_id_values) {
     $conditions = [];
     foreach ($this->sourceIdFields() as $field_name => $db_field) {
       if ($is_associative) {
-        // 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];
+        // 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];
+          }
           unset($source_id_values[$field_name]);
         }
       }
@@ -580,7 +584,8 @@ public function lookupDestinationIds(array $source_id_values) {
     }
 
     if (!empty($source_id_values)) {
-      throw new MigrateException("Extra unknown items in source IDs");
+      $var_dump = var_export($source_id_values, TRUE);
+      throw new MigrateException(sprintf("Extra unknown items in source IDs: %s", $var_dump));
     }
 
     $query = $this->getDatabase()->select($this->mapTableName(), 'map')
diff --git a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
index bc849916d7e2..001e14c74c8e 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
@@ -517,6 +517,8 @@ 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']));
@@ -527,14 +529,14 @@ public function testLookupDestinationIds() {
       $this->fail('Too many source IDs should throw');
     }
     catch (MigrateException $e) {
-      $this->assertEquals("Extra unknown items in source IDs", $e->getMessage());
+      $this->assertEquals("Extra unknown items in source IDs: array (\n  0 => 3,\n)", $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", $e->getMessage());
+      $this->assertEquals("Extra unknown items in source IDs: array (\n  'aaa' => '2',\n)", $e->getMessage());
     }
 
     // Verify that we are looking up by source_id_hash when all source IDs are
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index ea4eee69b2a5..4d4e18be489a 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -9710,6 +9710,38 @@
   'objectindex' => '7',
   'format' => '0',
 ))
+->values(array(
+  'lid' => '1674',
+  'objectid' => '463',
+  'type' => 'item',
+  'property' => 'title',
+  'objectindex' => '463',
+  'format' => '0',
+))
+->values(array(
+  'lid' => '1675',
+  'objectid' => '463',
+  'type' => 'item',
+  'property' => 'description',
+  'objectindex' => '463',
+  'format' => '0',
+))
+->values(array(
+  'lid' => '1676',
+  'objectid' => '138',
+  'type' => 'item',
+  'property' => 'title',
+  'objectindex' => '138',
+  'format' => '0',
+))
+->values(array(
+  'lid' => '1677',
+  'objectid' => '138',
+  'type' => 'item',
+  'property' => 'description',
+  'objectindex' => '138',
+  'format' => '0',
+))
 ->execute();
 
 $connection->schema()->createTable('i18n_variable', array(
@@ -22176,6 +22208,34 @@
   'source' => 'Forums',
   'version' => '1',
 ))
+->values(array(
+  'lid' => '1674',
+  'location' => 'item:463:title',
+  'textgroup' => 'menu',
+  'source' => 'fr - Test 1',
+  'version' => '1',
+))
+->values(array(
+  'lid' => '1675',
+  'location' => 'item:463:description',
+  'textgroup' => 'menu',
+  'source' => 'fr - Test menu link 1',
+  'version' => '1',
+))
+->values(array(
+  'lid' => '1676',
+  'location' => 'item:138:title',
+  'textgroup' => 'menu',
+  'source' => 'Test 1',
+  'version' => '1',
+))
+->values(array(
+  'lid' => '1677',
+  'location' => 'item:138:description',
+  'textgroup' => 'menu',
+  'source' => 'Test menu link 1',
+  'version' => '1',
+))
 ->execute();
 
 $connection->schema()->createTable('locales_target', array(
@@ -27705,7 +27765,7 @@
   'link_path' => 'user/login',
   'router_path' => 'user/login',
   'link_title' => 'Test 1',
-  'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 1";}}',
+  'options' => 'a:2:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 1";}s:8:"langcode";s:2:"en";}',
   'module' => 'menu',
   'hidden' => '0',
   'external' => '0',
@@ -33827,6 +33887,33 @@
   'p9' => '0',
   'updated' => '0',
 ))
+->values(array(
+  'menu_name' => 'secondary-links',
+  'mlid' => '463',
+  'plid' => '139',
+  'link_path' => 'user/login',
+  'router_path' => 'user/login',
+  'link_title' => 'fr - Test 1',
+  'options' => 'a:3:{s:10:"attributes";a:1:{s:5:"title";s:21:"fr - Test menu link 1";}s:8:"langcode";s:2:"fr";s:5:"alter";b:1;}',
+  'module' => 'menu',
+  'hidden' => '0',
+  'external' => '0',
+  'has_children' => '0',
+  'expanded' => '0',
+  'weight' => '-49',
+  'depth' => '2',
+  'customized' => '1',
+  'p1' => '139',
+  'p2' => '459',
+  'p3' => '0',
+  'p4' => '0',
+  'p5' => '0',
+  'p6' => '0',
+  'p7' => '0',
+  'p8' => '0',
+  'p9' => '0',
+  'updated' => '0',
+))
 ->execute();
 
 $connection->schema()->createTable('menu_router', array(
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
index a526de77e95f..798f0290d84a 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6ReviewPageTest.php
@@ -89,6 +89,7 @@ protected function getAvailablePaths() {
       'filefield_meta',
       'help',
       'i18n',
+      'i18nmenu',
       'i18nstrings',
       'imageapi',
       'imageapi_gd',
@@ -123,7 +124,6 @@ protected function getMissingPaths() {
       'i18nblocks',
       'i18ncck',
       'i18ncontent',
-      'i18nmenu',
       'i18npoll',
       'i18nprofile',
       'i18nsync',
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
index 841b27c310e7..f32e60a61057 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
@@ -68,7 +68,7 @@ protected function getEntityCounts() {
       'file' => 8,
       'filter_format' => 7,
       'image_style' => 5,
-      'language_content_settings' => 2,
+      'language_content_settings' => 3,
       'migration' => 105,
       'node' => 17,
       // The 'book' module provides the 'book' node type, and the migration
@@ -85,7 +85,7 @@ protected function getEntityCounts() {
       'tour' => 4,
       'user' => 7,
       'user_role' => 6,
-      'menu_link_content' => 9,
+      'menu_link_content' => 10,
       'view' => 16,
       'date_format' => 11,
       'entity_form_display' => 29,
@@ -106,7 +106,7 @@ protected function getEntityCountsIncremental() {
     $counts['entity_view_display'] = 53;
     $counts['entity_view_mode'] = 14;
     $counts['file'] = 9;
-    $counts['menu_link_content'] = 10;
+    $counts['menu_link_content'] = 11;
     $counts['node'] = 18;
     $counts['taxonomy_term'] = 9;
     $counts['user'] = 8;
@@ -131,6 +131,7 @@ protected function getAvailablePaths() {
       'filefield',
       'filter',
       'forum',
+      'i18nmenu',
       'i18ntaxonomy',
       'imagecache',
       'imagefield',
@@ -175,7 +176,6 @@ protected function getMissingPaths() {
       'i18nblocks',
       'i18ncck',
       'i18ncontent',
-      'i18nmenu',
       // This module is in the missing path list because it is installed on the
       // source site but it is not installed on the destination site.
       'i18nprofile',
diff --git a/core/modules/system/src/Plugin/migrate/source/Extension.php b/core/modules/system/src/Plugin/migrate/source/Extension.php
new file mode 100644
index 000000000000..379939110d07
--- /dev/null
+++ b/core/modules/system/src/Plugin/migrate/source/Extension.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Drupal\system\Plugin\migrate\source;
+
+use Drupal\migrate\Row;
+use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+
+/**
+ * Gets system data for a legacy extension.
+ *
+ * @MigrateSource(
+ *   id = "extension",
+ *   source_module = "system"
+ * )
+ */
+class Extension extends DrupalSqlBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    $query = $this->select('system', 's')
+      ->fields('s');
+
+    if (isset($this->configuration['name'])) {
+      $query->condition('name', (array) $this->configuration['name'], 'IN');
+    }
+    return $query;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function fields() {
+    $fields = [
+      'filename' => $this->t('Filename'),
+      'name' => $this->t('Name'),
+      'type' => $this->t('Type'),
+      'owner' => $this->t('Owner'),
+      'status' => $this->t('Status'),
+      'throttle' => $this->t('Throttle'),
+      'bootstrap' => $this->t('Bootstrap'),
+      'schema_version' => $this->t('Schema version'),
+      'weight' => $this->t('Weight'),
+      'info' => $this->t('Information array'),
+    ];
+    return $fields;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function prepareRow(Row $row) {
+    $row->setSourceProperty('info', unserialize($row->getSourceProperty('info')));
+    return parent::prepareRow($row);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getIds() {
+    $ids['name']['type'] = 'string';
+    return $ids;
+  }
+
+}
diff --git a/core/modules/system/tests/src/Kernel/Plugin/migrate/source/ExtensionTest.php b/core/modules/system/tests/src/Kernel/Plugin/migrate/source/ExtensionTest.php
new file mode 100644
index 000000000000..c6576019a760
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Plugin/migrate/source/ExtensionTest.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Plugin\migrate\source;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests legacy extension source plugin.
+ *
+ * @covers \Drupal\system\Plugin\migrate\source\Extension
+ * @group migrate_drupal
+ */
+class ExtensionTest extends MigrateSqlSourceTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'migrate_drupal'];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function providerSource() {
+    $test = [];
+
+    $test[0]['source_data']['system'] = [
+      [
+        'filename' => 'sites/all/modules/i18n/i18nmenu/i18nmenu.module',
+        'name' => 'i18nmenu',
+        'type' => 'module',
+        'owner' => '',
+        'status' => '1',
+        'throttle' => '0',
+        'bootstrap' => '0',
+        'schema_version' => '0',
+        'weight' => '0',
+        'info' => 'a:10:{s:4:"name";s:16:"Menu translation";s:11:"description";s:40:"Supports translatable custom menu items.";s:12:"dependencies";a:4:{i:0;s:4:"i18n";i:1;s:4:"menu";i:2;s:10:"i18nblocks";i:3;s:11:"i18nstrings";}s:7:"package";s:13:"Multilanguage";s:4:"core";s:3:"6.x";s:7:"version";s:8:"6.x-1.10";s:7:"project";s:4:"i18n";s:9:"datestamp";s:10:"1318336004";s:10:"dependents";a:0:{}s:3:"php";s:5:"4.3.5";},',
+      ],
+      [
+        'filename' => 'sites/all/modules/variable/variable.module ',
+        'name' => 'variable',
+        'type' => 'module',
+        'owner' => '',
+        'status' => '1',
+        'throttle' => '0',
+        'bootstrap' => '0',
+        'schema_version' => '-1',
+        'weight' => '0',
+        'info' => 'a:9:{s:4:"name";s:12:"Variable API";s:11:"description";s:12:"Variable API";s:4:"core";s:3:"6.x";s:7:"version";s:14:"6.x-1.0-alpha1";s:7:"project";s:8:"variable";s:9:"datestamp";s:10:"1414059742";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}s:3:"php";s:5:"4.3.5";}',
+      ],
+    ];
+
+    $info = unserialize('a:9:{s:4:"name";s:12:"Variable API";s:11:"description";s:12:"Variable API";s:4:"core";s:3:"6.x";s:7:"version";s:14:"6.x-1.0-alpha1";s:7:"project";s:8:"variable";s:9:"datestamp";s:10:"1414059742";s:12:"dependencies";a:0:{}s:10:"dependents";a:0:{}s:3:"php";s:5:"4.3.5";}');
+    $test[0]['expected_results'] = [
+      [
+        'filename' => 'sites/all/modules/variable/variable.module ',
+        'name' => 'variable',
+        'type' => 'module',
+        'owner' => '',
+        'status' => '1',
+        'throttle' => '0',
+        'bootstrap' => '0',
+        'schema_version' => '-1',
+        'weight' => '0',
+        'info' => $info,
+      ],
+    ];
+
+    $test[0]['expected_count'] = NULL;
+    $test[0]['configuration'] = [
+      'name' => 'variable',
+    ];
+
+    return $test;
+  }
+
+}
-- 
GitLab