reverted: --- b/core/modules/menu_link_content/migration_templates/d6_i18n_menu_links.yml +++ /dev/null @@ -1,37 +0,0 @@ -id: d6_i18n_menu_links -label: Menu links -migration_tags: - - Drupal 6 -source: - plugin: d6_i18n_menu_link -process: - id: mlid - langcode: language - title: title - description: description - menu_name: - - - plugin: migration - # The menu migration is in the system module. - migration: menu - source: menu_name - - - plugin: static_map - map: - management: admin - bypass: true - 'link/uri': - plugin: link_uri - source: - - link_path - 'link/options': options -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 reverted: --- b/core/modules/menu_link_content/src/Plugin/migrate/source/d6/I18nMenuLink.php +++ /dev/null @@ -1,117 +0,0 @@ -values()); - } - - /** - * {@inheritdoc} - */ - public function count() { - return $this->initializeIterator()->count(); - } - - /** - * Returns the menu link translation values. - * - * @return array - * Each result is an associative array where the values are the menu IDs - * and the translations for the title and description, if available. If not - * available then the default language values are used. - */ - protected function values() { - $values = []; - $query = $this->prepareQuery(); - $result = $query->execute()->fetchAll(); - $cnt = count($result); - for ($i = 0; $i < $cnt; $i++) { - if (isset($result[$i])) { - if ($result[$i]['description'] == NULL) { - // Check next result for the description value. - $j = $i + 1; - if (isset($result[$j])) { - // If the same menu_link, then this is a description translation. - if ($result[$i]['mlid'] == $result[$j]['mlid'] && - $result[$i]['language'] == $result[$j]['language']) { - if ($result[$j]['description'] != NULL) { - $result[$i]['description'] = $result[$j]['description']; - unset($result[$j]); - } - } - else { - // Get the description fom the options array. - $tmp = unserialize($result[$i]['options']); - $result[$i]['description'] = Unicode::truncate($tmp['attributes']['title'], 255); - } - } - } - $values[] = $result[$i]; - } - } - return $values; - } - - /** - * {@inheritdoc} - */ - public function query() { - $query = $this->select('menu_links', 'ml') - ->fields('ml', ['mlid', 'link_path', 'options']) - ->fields('i18n', ['objectid']) - ->fields('lt', ['language']) - ->condition('i18n.type', 'item') - ->condition('ml.module', 'menu') - ->orderBy('mlid', 'language', 'title'); - $query->addExpression(self::TITLE, 'title'); - $query->addExpression(self::DESCRIPTION, 'description'); - $query->addField('lt', 'lid', 'lt.lid'); - $query->Join('i18n_strings', 'i18n', 'i18n.objectid = ml.mlid'); - $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid'); - return $query; - } - - /** - * {@inheritdoc} - */ - public function fields() { - return [ - 'mlid' => t('The menu link ID.'), - 'language' => $this->t('Language for this menu.'), - 'title' => $this->t('Menu link title.'), - 'description' => $this->t('Menu link description.'), - 'link_path' => t('The Drupal path or external path this link points to.'), - 'options' => t('A serialized array of options to set on the URL, such as a query string or HTML attributes.'), - ]; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['mlid']['type'] = 'integer'; - $ids['language']['type'] = 'string'; - return $ids; - } - -} reverted: --- b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateI18nMenuLinkTest.php +++ /dev/null @@ -1,72 +0,0 @@ -installSchema('system', ['router']); - $this->installEntitySchema('menu_link_content'); - $this->executeMigrations([ - 'language', - 'd6_menu', - 'd6_menu_links', - 'd6_i18n_menu_links', - ]); - } - - /** - * Tests migration of menu links. - */ - public function testMenuLinks() { - $menu_link = MenuLinkContent::load(139)->getTranslation('fr'); - $this->assertTrue(TRUE); - - $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->assertSame(TRUE, $menu_link->isEnabled()); - $this->assertSame(TRUE, $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->assertSame('Test 2', $menu_link->getTitle()); - $this->assertSame('zu - Test menu link 2', $menu_link->getDescription()); - $this->assertSame('secondary-links', $menu_link->getMenuName()); - $this->assertSame(TRUE, $menu_link->isEnabled()); - $this->assertSame(TRUE, $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->assertSame('fr - Drupal.org', $menu_link->getTitle()); - $this->assertNull($menu_link->getDescription()); - $this->assertSame('secondary-links', $menu_link->getMenuName()); - $this->assertSame(TRUE, $menu_link->isEnabled()); - $this->assertSame(FALSE, $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()); - } - -} reverted: --- b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/I18nMenuLinkSourceTest.php +++ /dev/null @@ -1,162 +0,0 @@ - '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', - 'description' => 'Test menu link 1', - ], - [ - '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', - 'description' => 'Test menu link 2', - ], - ]; - $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' => 138, - 'type' => 'item', - 'property' => 'description', - 'objectindex' => 0, - 'format' => 0, - ] - ]; - $test[0]['source_data']['locales_target'] = [ - [ - 'lid' => 1, - 'language' => 'fr', - 'translation' => 'fr - title translation', - 'plid' => 0, - 'plural' => 0, - 'u18n_status' => 0, - ], - [ - 'lid' => 2, - 'language' => 'fr', - 'translation' => 'fr - description translation', - 'plid' => 0, - 'plural' => 0, - 'u18n_status' => 0, - ], - [ - 'lid' => 3, - 'language' => 'zu', - 'translation' => 'zu - description translation', - 'plid' => 0, - 'plural' => 0, - 'u18n_status' => 0, - ], - ]; - - $test[0]['expected_results'] = [ - [ - 'mlid' => 138, - 'link_path' => 'admin', - 'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 1";}}', - 'objectid' => 138, - 'language' => 'zu', - 'ltlid' => 3, - 'title' => 'Test 1', - 'description' => 'zu - description translation', - ], - [ - 'mlid' => 139, - 'link_path' => 'admin/modules', - 'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 2";}}', - 'objectid' => 139, - 'language' => 'fr', - 'ltlid' => 1, - 'title' => 'fr - title translation', - 'description' => 'fr - description translation', - ], - ]; - - return $test; - } - -} diff -u b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php --- b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -318,7 +318,7 @@ 'source_module' => 'menu', 'destination_module' => 'menu_link_content', ], - 'd6_i18n_menu_links' => [ + 'd6_menu_links_translation' => [ 'source_module' => 'i18n', 'destination_module' => 'menu_link_content', ], only in patch2: unchanged: --- /dev/null +++ b/core/modules/menu_link_content/migration_templates/d6_menu_links_translation.yml @@ -0,0 +1,37 @@ +id: d6_menu_links_translation +label: Menu links +migration_tags: + - Drupal 6 +source: + plugin: d6_menu_link_translation +process: + id: mlid + langcode: language + title: title + description: description + menu_name: + - + plugin: migration + # The menu migration is in the system module. + migration: menu + source: menu_name + - + plugin: static_map + map: + management: admin + bypass: true + 'link/uri': + plugin: link_uri + source: + - link_path + 'link/options': options +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 only in patch2: unchanged: --- /dev/null +++ b/core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php @@ -0,0 +1,117 @@ +values()); + } + + /** + * {@inheritdoc} + */ + public function count() { + return $this->initializeIterator()->count(); + } + + /** + * Returns the menu link translation values. + * + * @return array + * Each result is an associative array where the values are the menu IDs + * and the translations for the title and description, if available. If not + * available then the default language values are used. + */ + protected function values() { + $values = []; + $query = $this->prepareQuery(); + $result = $query->execute()->fetchAll(); + $cnt = count($result); + for ($i = 0; $i < $cnt; $i++) { + if (isset($result[$i])) { + if ($result[$i]['description'] == NULL) { + // Check next result for the description value. + $j = $i + 1; + if (isset($result[$j])) { + // If the same menu_link, then this is a description translation. + if ($result[$i]['mlid'] == $result[$j]['mlid'] && + $result[$i]['language'] == $result[$j]['language']) { + if ($result[$j]['description'] != NULL) { + $result[$i]['description'] = $result[$j]['description']; + unset($result[$j]); + } + } + else { + // Get the description fom the options array. + $tmp = unserialize($result[$i]['options']); + $result[$i]['description'] = Unicode::truncate($tmp['attributes']['title'], 255); + } + } + } + $values[] = $result[$i]; + } + } + return $values; + } + + /** + * {@inheritdoc} + */ + public function query() { + $query = $this->select('menu_links', 'ml') + ->fields('ml', ['mlid', 'link_path', 'options']) + ->fields('i18n', ['objectid']) + ->fields('lt', ['language']) + ->condition('i18n.type', 'item') + ->condition('ml.module', 'menu') + ->orderBy('mlid', 'language', 'title'); + $query->addExpression(self::TITLE, 'title'); + $query->addExpression(self::DESCRIPTION, 'description'); + $query->addField('lt', 'lid', 'lt.lid'); + $query->Join('i18n_strings', 'i18n', 'i18n.objectid = ml.mlid'); + $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid'); + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'mlid' => t('The menu link ID.'), + 'language' => $this->t('Language for this menu.'), + 'title' => $this->t('Menu link title.'), + 'description' => $this->t('Menu link description.'), + 'link_path' => t('The Drupal path or external path this link points to.'), + 'options' => t('A serialized array of options to set on the URL, such as a query string or HTML attributes.'), + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['mlid']['type'] = 'integer'; + $ids['language']['type'] = 'string'; + return $ids; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/menu_link_content/tests/src/Kernel/Migrate/d6/MigrateMenuLinkTranslationTest.php @@ -0,0 +1,72 @@ +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() { + $menu_link = MenuLinkContent::load(139)->getTranslation('fr'); + $this->assertTrue(TRUE); + + $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->assertSame(TRUE, $menu_link->isEnabled()); + $this->assertSame(TRUE, $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->assertSame('Test 2', $menu_link->getTitle()); + $this->assertSame('zu - Test menu link 2', $menu_link->getDescription()); + $this->assertSame('secondary-links', $menu_link->getMenuName()); + $this->assertSame(TRUE, $menu_link->isEnabled()); + $this->assertSame(TRUE, $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->assertSame('fr - Drupal.org', $menu_link->getTitle()); + $this->assertNull($menu_link->getDescription()); + $this->assertSame('secondary-links', $menu_link->getMenuName()); + $this->assertSame(TRUE, $menu_link->isEnabled()); + $this->assertSame(FALSE, $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()); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/source/d6/MenuLinkSourceTranslationTest.php @@ -0,0 +1,162 @@ + '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', + 'description' => 'Test menu link 1', + ], + [ + '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', + 'description' => 'Test menu link 2', + ], + ]; + $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' => 138, + 'type' => 'item', + 'property' => 'description', + 'objectindex' => 0, + 'format' => 0, + ], + ]; + $test[0]['source_data']['locales_target'] = [ + [ + 'lid' => 1, + 'language' => 'fr', + 'translation' => 'fr - title translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + [ + 'lid' => 2, + 'language' => 'fr', + 'translation' => 'fr - description translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + [ + 'lid' => 3, + 'language' => 'zu', + 'translation' => 'zu - description translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + ]; + + $test[0]['expected_results'] = [ + [ + 'mlid' => 138, + 'link_path' => 'admin', + 'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 1";}}', + 'objectid' => 138, + 'language' => 'zu', + 'ltlid' => 3, + 'title' => 'Test 1', + 'description' => 'zu - description translation', + ], + [ + 'mlid' => 139, + 'link_path' => 'admin/modules', + 'options' => 'a:1:{s:10:"attributes";a:1:{s:5:"title";s:16:"Test menu link 2";}}', + 'objectid' => 139, + 'language' => 'fr', + 'ltlid' => 1, + 'title' => 'fr - title translation', + 'description' => 'fr - description translation', + ], + ]; + + return $test; + } + +}