Loading core/modules/content_translation/migrations/d7_menu_links_localized.yml 0 → 100644 +46 −0 Original line number Diff line number Diff line id: d7_menu_links_localized label: Menu links migration_tags: - Drupal 7 - Content - Multilingual source: plugin: d7_menu_link_localized constants: bundle: menu_link_content process: skip_translation: plugin: skip_on_empty method: row source: skip_source_translation exists: - plugin: migration_lookup migration: d7_menu_links source: mlid - plugin: skip_on_empty method: row id: mlid langcode: language title: link_title description: description menu_name: - plugin: migration_lookup migration: d7_menu source: menu_name - plugin: skip_on_empty method: row destination: plugin: entity:menu_link_content no_stub: true translations: true destination_module: content_translation migration_dependencies: required: - language - d7_language_content_menu_settings - d7_menu_links core/modules/content_translation/migrations/d7_menu_links_translation.yml 0 → 100644 +50 −0 Original line number Diff line number Diff line id: d7_menu_links_translation label: Menu links migration_tags: - Drupal 7 - Content - Multilingual source: plugin: d7_menu_link_translation process: exists: - plugin: migration_lookup migration: d7_menu_links source: mlid - plugin: skip_on_empty method: row id: mlid # Use the language from the locales_target table. 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 destination: plugin: entity:menu_link_content default_bundle: menu_link_content no_stub: true translations: true migration_dependencies: required: - language - d7_language_content_menu_settings - d7_menu_links core/modules/content_translation/migrations/state/content_translation.migrate_drupal.yml +2 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ finished: - content_translation locale: content_translation menu: content_translation # menu links. i18n_menu: content_translation statistics: statistics # Node revision translations. node: content_translation Loading @@ -36,9 +38,6 @@ not_finished: # @TODO: Move to finished when remaining Drupal 7 i18n issues are resolved. # See https://www.drupal.org/project/drupal/issues/2208401 i18n: content_translation # Menu links. # See https://www.drupal.org/project/drupal/issues/3008028 i18n_menu: content_translation # @TODO: Remove when taxonomy term field translations are migrated. # See https://www.drupal.org/project/drupal/issues/3073050 i18n_taxonomy: content_translation core/modules/menu_link_content/migrations/d7_menu_links.yml +8 −0 Original line number Diff line number Diff line Loading @@ -9,7 +9,15 @@ source: constants: bundle: menu_link_content process: skip_translation: plugin: skip_on_empty method: row source: skip_translation id: mlid langcode: plugin: default_value source: language default_value: und bundle: 'constants/bundle' title: link_title description: description Loading core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php +62 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ public function query() { * {@inheritdoc} */ public function fields() { return [ $fields = [ 'menu_name' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."), 'mlid' => t('The menu link ID (mlid) is the integer primary key.'), 'plid' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'), Loading @@ -67,12 +67,48 @@ public function fields() { 'p9' => t('The ninth mlid in the materialized path. See p1.'), 'updated' => t('Flag that indicates that this link was generated during the update from Drupal 5.'), ]; $schema = $this->getDatabase()->schema(); if ($schema->fieldExists('menu_links', 'language')) { $fields['language'] = $this->t("Menu link language code."); } if ($schema->fieldExists('menu_links', 'i18n_tsid')) { $fields['i18n_tsid'] = $this->t("Translation set id."); } return $fields; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { // In Drupal 7 a language neutral menu_link can be translated. The menu // link is treated as if it is in the site default language. So, here // we look to see if this menu link has a translation and if so, the // language is changed to the default language. With the language set // the entity API will allow the saving of the translations. if ($row->hasSourceProperty('language') && $row->getSourceProperty('language') == 'und' && $this->hasTranslation($row->getSourceProperty('mlid'))) { $default_language = $this->variableGet('language_default', (object) ['language' => 'und']); $default_language = $default_language->language; $row->setSourceProperty('language', $default_language); } // If this menu link is part of translation set skip the translations. The // translations are migrated in d7_menu_link_localized.yml. $row->setSourceProperty('skip_translation', TRUE); if ($row->hasSourceProperty('i18n_tsid') && $row->getSourceProperty('i18n_tsid') != 0) { $source_mlid = $this->select('menu_links', 'ml') ->fields('ml', ['mlid']) ->condition('i18n_tsid', $row->getSourceProperty('i18n_tsid')) ->orderBy('mlid') ->range(0, 1) ->execute() ->fetchField(); if ($source_mlid !== $row->getSourceProperty('mlid')) { $row->setSourceProperty('skip_translation', FALSE); } } $row->setSourceProperty('options', unserialize($row->getSourceProperty('options'))); $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden')); $row->setSourceProperty('description', Unicode::truncate($row->getSourceProperty('options/attributes/title'), 255)); Loading @@ -80,6 +116,31 @@ public function prepareRow(Row $row) { return parent::prepareRow($row); } /** * Determines if this menu_link has an i18n translation. * * @param string $mlid * The menu id. * * @return bool * True if the menu_link has an i18n translation. */ public function hasTranslation($mlid) { if ($this->getDatabase()->schema()->tableExists('i18n_string')) { $results = $this->select('i18n_string', 'i18n') ->fields('i18n') ->condition('textgroup', 'menu') ->condition('type', 'item') ->condition('objectid', $mlid) ->execute() ->fetchAll(); if ($results) { return TRUE; } } return FALSE; } /** * {@inheritdoc} */ Loading Loading
core/modules/content_translation/migrations/d7_menu_links_localized.yml 0 → 100644 +46 −0 Original line number Diff line number Diff line id: d7_menu_links_localized label: Menu links migration_tags: - Drupal 7 - Content - Multilingual source: plugin: d7_menu_link_localized constants: bundle: menu_link_content process: skip_translation: plugin: skip_on_empty method: row source: skip_source_translation exists: - plugin: migration_lookup migration: d7_menu_links source: mlid - plugin: skip_on_empty method: row id: mlid langcode: language title: link_title description: description menu_name: - plugin: migration_lookup migration: d7_menu source: menu_name - plugin: skip_on_empty method: row destination: plugin: entity:menu_link_content no_stub: true translations: true destination_module: content_translation migration_dependencies: required: - language - d7_language_content_menu_settings - d7_menu_links
core/modules/content_translation/migrations/d7_menu_links_translation.yml 0 → 100644 +50 −0 Original line number Diff line number Diff line id: d7_menu_links_translation label: Menu links migration_tags: - Drupal 7 - Content - Multilingual source: plugin: d7_menu_link_translation process: exists: - plugin: migration_lookup migration: d7_menu_links source: mlid - plugin: skip_on_empty method: row id: mlid # Use the language from the locales_target table. 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 destination: plugin: entity:menu_link_content default_bundle: menu_link_content no_stub: true translations: true migration_dependencies: required: - language - d7_language_content_menu_settings - d7_menu_links
core/modules/content_translation/migrations/state/content_translation.migrate_drupal.yml +2 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ finished: - content_translation locale: content_translation menu: content_translation # menu links. i18n_menu: content_translation statistics: statistics # Node revision translations. node: content_translation Loading @@ -36,9 +38,6 @@ not_finished: # @TODO: Move to finished when remaining Drupal 7 i18n issues are resolved. # See https://www.drupal.org/project/drupal/issues/2208401 i18n: content_translation # Menu links. # See https://www.drupal.org/project/drupal/issues/3008028 i18n_menu: content_translation # @TODO: Remove when taxonomy term field translations are migrated. # See https://www.drupal.org/project/drupal/issues/3073050 i18n_taxonomy: content_translation
core/modules/menu_link_content/migrations/d7_menu_links.yml +8 −0 Original line number Diff line number Diff line Loading @@ -9,7 +9,15 @@ source: constants: bundle: menu_link_content process: skip_translation: plugin: skip_on_empty method: row source: skip_translation id: mlid langcode: plugin: default_value source: language default_value: und bundle: 'constants/bundle' title: link_title description: description Loading
core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php +62 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ public function query() { * {@inheritdoc} */ public function fields() { return [ $fields = [ 'menu_name' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."), 'mlid' => t('The menu link ID (mlid) is the integer primary key.'), 'plid' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'), Loading @@ -67,12 +67,48 @@ public function fields() { 'p9' => t('The ninth mlid in the materialized path. See p1.'), 'updated' => t('Flag that indicates that this link was generated during the update from Drupal 5.'), ]; $schema = $this->getDatabase()->schema(); if ($schema->fieldExists('menu_links', 'language')) { $fields['language'] = $this->t("Menu link language code."); } if ($schema->fieldExists('menu_links', 'i18n_tsid')) { $fields['i18n_tsid'] = $this->t("Translation set id."); } return $fields; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { // In Drupal 7 a language neutral menu_link can be translated. The menu // link is treated as if it is in the site default language. So, here // we look to see if this menu link has a translation and if so, the // language is changed to the default language. With the language set // the entity API will allow the saving of the translations. if ($row->hasSourceProperty('language') && $row->getSourceProperty('language') == 'und' && $this->hasTranslation($row->getSourceProperty('mlid'))) { $default_language = $this->variableGet('language_default', (object) ['language' => 'und']); $default_language = $default_language->language; $row->setSourceProperty('language', $default_language); } // If this menu link is part of translation set skip the translations. The // translations are migrated in d7_menu_link_localized.yml. $row->setSourceProperty('skip_translation', TRUE); if ($row->hasSourceProperty('i18n_tsid') && $row->getSourceProperty('i18n_tsid') != 0) { $source_mlid = $this->select('menu_links', 'ml') ->fields('ml', ['mlid']) ->condition('i18n_tsid', $row->getSourceProperty('i18n_tsid')) ->orderBy('mlid') ->range(0, 1) ->execute() ->fetchField(); if ($source_mlid !== $row->getSourceProperty('mlid')) { $row->setSourceProperty('skip_translation', FALSE); } } $row->setSourceProperty('options', unserialize($row->getSourceProperty('options'))); $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden')); $row->setSourceProperty('description', Unicode::truncate($row->getSourceProperty('options/attributes/title'), 255)); Loading @@ -80,6 +116,31 @@ public function prepareRow(Row $row) { return parent::prepareRow($row); } /** * Determines if this menu_link has an i18n translation. * * @param string $mlid * The menu id. * * @return bool * True if the menu_link has an i18n translation. */ public function hasTranslation($mlid) { if ($this->getDatabase()->schema()->tableExists('i18n_string')) { $results = $this->select('i18n_string', 'i18n') ->fields('i18n') ->condition('textgroup', 'menu') ->condition('type', 'item') ->condition('objectid', $mlid) ->execute() ->fetchAll(); if ($results) { return TRUE; } } return FALSE; } /** * {@inheritdoc} */ Loading