Issue #3008025 by quietone: Migrate D7 i18n block translated strings
parent
98d7171509
commit
9444c6a26a
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\block\Plugin\migrate\source\d7;
|
||||||
|
|
||||||
|
use Drupal\block\Plugin\migrate\source\Block;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets i18n block data from source database.
|
||||||
|
*
|
||||||
|
* @MigrateSource(
|
||||||
|
* id = "d7_block_translation",
|
||||||
|
* source_module = "i18n_block"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class BlockTranslation extends Block {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function query() {
|
||||||
|
// Let the parent set the block table to use, but do not use the parent
|
||||||
|
// query. Instead build a query so can use an inner join to the selected
|
||||||
|
// block table.
|
||||||
|
parent::query();
|
||||||
|
$query = $this->select('i18n_string', 'i18n')
|
||||||
|
->fields('i18n')
|
||||||
|
->fields('b', [
|
||||||
|
'bid',
|
||||||
|
'module',
|
||||||
|
'delta',
|
||||||
|
'theme',
|
||||||
|
'status',
|
||||||
|
'weight',
|
||||||
|
'region',
|
||||||
|
'custom',
|
||||||
|
'visibility',
|
||||||
|
'pages',
|
||||||
|
'title',
|
||||||
|
'cache',
|
||||||
|
'i18n_mode',
|
||||||
|
])
|
||||||
|
->fields('lt', [
|
||||||
|
'lid',
|
||||||
|
'translation',
|
||||||
|
'language',
|
||||||
|
'plid',
|
||||||
|
'plural',
|
||||||
|
'i18n_status',
|
||||||
|
])
|
||||||
|
->condition('i18n_mode', 1);
|
||||||
|
$query->leftjoin($this->blockTable, 'b', ('b.delta = i18n.objectid'));
|
||||||
|
$query->leftjoin('locales_target', 'lt', 'lt.lid = i18n.lid');
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function fields() {
|
||||||
|
return [
|
||||||
|
'bid' => $this->t('The block numeric identifier.'),
|
||||||
|
'module' => $this->t('The module providing the block.'),
|
||||||
|
'delta' => $this->t("The block's delta."),
|
||||||
|
'theme' => $this->t('Which theme the block is placed in.'),
|
||||||
|
'status' => $this->t('Block enabled status'),
|
||||||
|
'weight' => $this->t('Block weight within region'),
|
||||||
|
'region' => $this->t('Theme region within which the block is set'),
|
||||||
|
'visibility' => $this->t('Visibility'),
|
||||||
|
'pages' => $this->t('Pages list.'),
|
||||||
|
'title' => $this->t('Block title.'),
|
||||||
|
'cache' => $this->t('Cache rule.'),
|
||||||
|
'i18n_mode' => $this->t('Multilingual mode'),
|
||||||
|
'lid' => $this->t('Language string ID'),
|
||||||
|
'textgroup' => $this->t('A module defined group of translations'),
|
||||||
|
'context' => $this->t('Full string ID for quick search: type:objectid:property.'),
|
||||||
|
'objectid' => $this->t('Object ID'),
|
||||||
|
'type' => $this->t('Object type for this string'),
|
||||||
|
'property' => $this->t('Object property for this string'),
|
||||||
|
'objectindex' => $this->t('Integer value of Object ID'),
|
||||||
|
'format' => $this->t('The {filter_format}.format of the string'),
|
||||||
|
'translation' => $this->t('Translation'),
|
||||||
|
'language' => $this->t('Language code'),
|
||||||
|
'plid' => $this->t('Parent lid'),
|
||||||
|
'plural' => $this->t('Plural index number'),
|
||||||
|
'i18n_status' => $this->t('Translation needs update'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIds() {
|
||||||
|
$ids['delta']['type'] = 'string';
|
||||||
|
$ids['delta']['alias'] = 'b';
|
||||||
|
$ids['language']['type'] = 'string';
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\block\Kernel\Migrate\d7;
|
||||||
|
|
||||||
|
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests migration of i18n block translations.
|
||||||
|
*
|
||||||
|
* @group migrate_drupal_7
|
||||||
|
*/
|
||||||
|
class MigrateBlockContentTranslationTest extends MigrateDrupal7TestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = [
|
||||||
|
'node',
|
||||||
|
'text',
|
||||||
|
'aggregator',
|
||||||
|
'book',
|
||||||
|
'block',
|
||||||
|
'comment',
|
||||||
|
'forum',
|
||||||
|
'views',
|
||||||
|
'block_content',
|
||||||
|
'config_translation',
|
||||||
|
'content_translation',
|
||||||
|
'language',
|
||||||
|
'statistics',
|
||||||
|
'taxonomy',
|
||||||
|
// Required for translation migrations.
|
||||||
|
'migrate_drupal_multilingual',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->installConfig(['block']);
|
||||||
|
$this->installConfig(['block_content']);
|
||||||
|
$this->installEntitySchema('block_content');
|
||||||
|
|
||||||
|
$this->executeMigrations([
|
||||||
|
'language',
|
||||||
|
'd7_filter_format',
|
||||||
|
'block_content_type',
|
||||||
|
'block_content_body_field',
|
||||||
|
'd7_custom_block',
|
||||||
|
'd7_user_role',
|
||||||
|
'd7_block',
|
||||||
|
'd7_block_translation',
|
||||||
|
]);
|
||||||
|
block_rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the migration of block title translation.
|
||||||
|
*/
|
||||||
|
public function testBlockContentTranslation() {
|
||||||
|
/** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
|
||||||
|
$language_manager = $this->container->get('language_manager');
|
||||||
|
|
||||||
|
$config = $language_manager->getLanguageConfigOverride('fr', 'block.block.bartik_user_login');
|
||||||
|
$this->assertSame('fr - User login title', $config->get('settings.label'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -112,10 +112,10 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
||||||
public function testBlockMigration() {
|
public function testBlockMigration() {
|
||||||
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0, '', '0');
|
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0, '', '0');
|
||||||
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1, '', '0');
|
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1, '', '0');
|
||||||
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0, '', '0');
|
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0, 'User login title', 'visible');
|
||||||
$this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'footer_fifth', 'bartik', 10, '', '0');
|
$this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'footer_fifth', 'bartik', 10, '', '0');
|
||||||
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0, '', '0');
|
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0, '', '0');
|
||||||
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10, '', '0');
|
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10, 'User login title', 'visible');
|
||||||
|
|
||||||
// The d7_custom_block migration should have migrated a block containing a
|
// The d7_custom_block migration should have migrated a block containing a
|
||||||
// mildly amusing limerick. We'll need its UUID to determine
|
// mildly amusing limerick. We'll need its UUID to determine
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\block\Kernel\Plugin\migrate\source\d7;
|
||||||
|
|
||||||
|
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests i18n block source plugin.
|
||||||
|
*
|
||||||
|
* @covers \Drupal\block\Plugin\migrate\source\d7\BlockTranslation
|
||||||
|
*
|
||||||
|
* @group content_translation
|
||||||
|
*/
|
||||||
|
class BlockTranslationTest extends MigrateSqlSourceTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['block', 'migrate_drupal'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function providerSource() {
|
||||||
|
|
||||||
|
// The source data.
|
||||||
|
$tests[0]['source_data']['block'] = [
|
||||||
|
[
|
||||||
|
'bid' => 1,
|
||||||
|
'module' => 'system',
|
||||||
|
'delta' => 'main',
|
||||||
|
'theme' => 'bartik',
|
||||||
|
'status' => 1,
|
||||||
|
'weight' => 0,
|
||||||
|
'region' => 'content',
|
||||||
|
'custom' => '0',
|
||||||
|
'visibility' => 0,
|
||||||
|
'pages' => '',
|
||||||
|
'title' => '',
|
||||||
|
'cache' => -1,
|
||||||
|
'i18n_mode' => 0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'bid' => 2,
|
||||||
|
'module' => 'system',
|
||||||
|
'delta' => 'navigation',
|
||||||
|
'theme' => 'bartik',
|
||||||
|
'status' => 1,
|
||||||
|
'weight' => 0,
|
||||||
|
'region' => 'sidebar_first',
|
||||||
|
'custom' => '0',
|
||||||
|
'visibility' => 0,
|
||||||
|
'pages' => '',
|
||||||
|
'title' => 'Navigation',
|
||||||
|
'cache' => -1,
|
||||||
|
'i18n_mode' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$tests[0]['source_data']['block_role'] = [
|
||||||
|
[
|
||||||
|
'module' => 'block',
|
||||||
|
'delta' => 1,
|
||||||
|
'rid' => 2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'module' => 'block',
|
||||||
|
'delta' => 2,
|
||||||
|
'rid' => 2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'module' => 'block',
|
||||||
|
'delta' => 2,
|
||||||
|
'rid' => 100,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$tests[0]['source_data']['i18n_string'] = [
|
||||||
|
[
|
||||||
|
'lid' => 1,
|
||||||
|
'textgroup' => 'block',
|
||||||
|
'context' => '1',
|
||||||
|
'objectid' => 'navigation',
|
||||||
|
'type' => 'system',
|
||||||
|
'property' => 'title',
|
||||||
|
'objectindex' => 0,
|
||||||
|
'format' => '',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tests[0]['source_data']['locales_target'] = [
|
||||||
|
[
|
||||||
|
'lid' => 1,
|
||||||
|
'translation' => 'fr - Navigation',
|
||||||
|
'language' => 'fr',
|
||||||
|
'plid' => 0,
|
||||||
|
'plural' => 0,
|
||||||
|
'i18n_status' => 0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$tests[0]['source_data']['role'] = [
|
||||||
|
[
|
||||||
|
'rid' => 2,
|
||||||
|
'name' => 'authenticated user',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$tests[0]['source_data']['system'] = [
|
||||||
|
[
|
||||||
|
'filename' => 'modules/system/system.module',
|
||||||
|
'name' => 'system',
|
||||||
|
'type' => 'module',
|
||||||
|
'owner' => '',
|
||||||
|
'status' => '1',
|
||||||
|
'throttle' => '0',
|
||||||
|
'bootstrap' => '0',
|
||||||
|
'schema_version' => '7055',
|
||||||
|
'weight' => '0',
|
||||||
|
'info' => 'a:0:{}',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
// The expected results.
|
||||||
|
$tests[0]['expected_data'] = [
|
||||||
|
[
|
||||||
|
'bid' => 2,
|
||||||
|
'module' => 'system',
|
||||||
|
'delta' => 'navigation',
|
||||||
|
'theme' => 'bartik',
|
||||||
|
'status' => 1,
|
||||||
|
'weight' => 0,
|
||||||
|
'region' => 'sidebar_first',
|
||||||
|
'custom' => '0',
|
||||||
|
'visibility' => 0,
|
||||||
|
'pages' => '',
|
||||||
|
'title' => 'Navigation',
|
||||||
|
'cache' => -1,
|
||||||
|
'i18n_mode' => 1,
|
||||||
|
'lid' => 1,
|
||||||
|
'translation' => 'fr - Navigation',
|
||||||
|
'language' => 'fr',
|
||||||
|
'plid' => 0,
|
||||||
|
'plural' => 0,
|
||||||
|
'i18n_status' => 0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $tests;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
id: d7_block_translation
|
||||||
|
label: Block translation
|
||||||
|
migration_tags:
|
||||||
|
- Drupal 7
|
||||||
|
- Configuration
|
||||||
|
- Multilingual
|
||||||
|
source:
|
||||||
|
plugin: d7_block_translation
|
||||||
|
constants:
|
||||||
|
dest_label: 'settings/label'
|
||||||
|
process:
|
||||||
|
multilingual:
|
||||||
|
plugin: skip_on_empty
|
||||||
|
source: i18n_mode
|
||||||
|
method: row
|
||||||
|
langcode: language
|
||||||
|
property: constants/dest_label
|
||||||
|
translation: translation
|
||||||
|
id:
|
||||||
|
-
|
||||||
|
plugin: migration_lookup
|
||||||
|
migration: d7_block
|
||||||
|
source:
|
||||||
|
- module
|
||||||
|
- delta
|
||||||
|
-
|
||||||
|
plugin: skip_on_empty
|
||||||
|
method: row
|
||||||
|
# The plugin process is copied from d7_block.yml
|
||||||
|
plugin:
|
||||||
|
-
|
||||||
|
plugin: static_map
|
||||||
|
bypass: true
|
||||||
|
source:
|
||||||
|
- module
|
||||||
|
- delta
|
||||||
|
map:
|
||||||
|
book:
|
||||||
|
navigation: book_navigation
|
||||||
|
comment:
|
||||||
|
recent: views_block:comments_recent-block_1
|
||||||
|
forum:
|
||||||
|
active: forum_active_block
|
||||||
|
new: forum_new_block
|
||||||
|
# locale:
|
||||||
|
# 0: language_block
|
||||||
|
node:
|
||||||
|
syndicate: node_syndicate_block
|
||||||
|
search:
|
||||||
|
form: search_form_block
|
||||||
|
statistics:
|
||||||
|
popular: statistics_popular_block
|
||||||
|
system:
|
||||||
|
main: system_main_block
|
||||||
|
'powered-by': system_powered_by_block
|
||||||
|
user:
|
||||||
|
login: user_login_block
|
||||||
|
# 1: system_menu_block:tools
|
||||||
|
new: views_block:who_s_new-block_1
|
||||||
|
online: views_block:who_s_online-who_s_online_block
|
||||||
|
-
|
||||||
|
plugin: block_plugin_id
|
||||||
|
-
|
||||||
|
plugin: skip_on_empty
|
||||||
|
method: row
|
||||||
|
# The theme process is copied from d7_block.yml
|
||||||
|
theme:
|
||||||
|
plugin: block_theme
|
||||||
|
source:
|
||||||
|
- theme
|
||||||
|
- default_theme
|
||||||
|
- admin_theme
|
||||||
|
destination:
|
||||||
|
plugin: entity:block
|
||||||
|
migration_dependencies:
|
||||||
|
optional:
|
||||||
|
- d7_block
|
File diff suppressed because it is too large
Load Diff
|
@ -65,6 +65,7 @@ class MigrateUpgrade7ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
|
||||||
'filter',
|
'filter',
|
||||||
'forum',
|
'forum',
|
||||||
'image',
|
'image',
|
||||||
|
'i18n_block',
|
||||||
'language',
|
'language',
|
||||||
'link',
|
'link',
|
||||||
'list',
|
'list',
|
||||||
|
@ -141,7 +142,6 @@ class MigrateUpgrade7ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
|
||||||
'entity_translation_i18n_menu',
|
'entity_translation_i18n_menu',
|
||||||
'entity_translation_upgrade',
|
'entity_translation_upgrade',
|
||||||
'i18n',
|
'i18n',
|
||||||
'i18n_block',
|
|
||||||
'i18n_contact',
|
'i18n_contact',
|
||||||
'i18n_field',
|
'i18n_field',
|
||||||
'i18n_forum',
|
'i18n_forum',
|
||||||
|
|
Loading…
Reference in New Issue