From d88f334803e820f14010b79a1a2ed705cd9eceeb Mon Sep 17 00:00:00 2001 From: catch Date: Tue, 22 Jun 2021 15:34:12 +0100 Subject: [PATCH] Issue #3103031 by quietone, alexpott, heddn, Wim Leers: Add bundle to the sourceIDs to FieldOptionTranslation source plugin --- .../process/d7/FieldOptionTranslation.php | 1 + .../source/d7/FieldOptionTranslation.php | 1 + ...rateFieldInstanceOptionTranslationTest.php | 86 +++++++ .../d7/MigrateFieldOptionTranslationTest.php | 42 ++- .../migrate_drupal/tests/fixtures/drupal7.php | 242 ++++++++++++++++++ .../tests/src/Functional/d7/Upgrade7Test.php | 4 +- 6 files changed, 373 insertions(+), 3 deletions(-) create mode 100644 core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceOptionTranslationTest.php diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldOptionTranslation.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldOptionTranslation.php index a7208bec1b1..3831bfcb596 100644 --- a/core/modules/field/src/Plugin/migrate/process/d7/FieldOptionTranslation.php +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldOptionTranslation.php @@ -42,6 +42,7 @@ class FieldOptionTranslation extends ProcessPluginBase { break; default: + $new_allowed_values = $allowed_values; } } return ["settings.allowed_values.$translation_key", $new_allowed_values]; diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldOptionTranslation.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldOptionTranslation.php index 21a8bbea6e8..5569541d2d4 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldOptionTranslation.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldOptionTranslation.php @@ -75,6 +75,7 @@ class FieldOptionTranslation extends Field { [ 'language' => ['type' => 'string'], 'property' => ['type' => 'string'], + 'bundle' => ['type' => 'string'], ]; } diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceOptionTranslationTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceOptionTranslationTest.php new file mode 100644 index 00000000000..10ee6dfe70f --- /dev/null +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceOptionTranslationTest.php @@ -0,0 +1,86 @@ +installConfig(['node']); + $this->executeMigration('language'); + $this->migrateFields(); + $this->executeMigrations([ + 'd7_field_option_translation', + 'd7_field_instance_option_translation', + ]); + } + + /** + * Migrate field instance option translations. + */ + public function testFieldInstanceOptionTranslation() { + $language_manager = $this->container->get('language_manager'); + + /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */ + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.blog.field_boolean'); + $this->assertNull($config_translation->get('settings')); + + $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.field.node.blog.field_boolean'); + $option_translation = [ + 'off_label' => 'is - Off', + 'on_label' => 'is - 1', + ]; + + $this->assertSame($option_translation, $config_translation->get('settings')); + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_content_type.field_boolean'); + $this->assertNull($config_translation->get('settings')); + + $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.field.node.test_content_type.field_boolean'); + $this->assertSame($option_translation, $config_translation->get('settings')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.article.field_checkbox'); + $option_translation = [ + 'off_label' => 'fr - Stop', + 'on_label' => 'Go', + ]; + $this->assertSame($option_translation, $config_translation->get('settings')); + + $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.field.node.article.field_checkbox'); + $option_translation = [ + 'off_label' => 'is - Stop', + 'on_label' => 'is - Go', + ]; + $this->assertSame($option_translation, $config_translation->get('settings')); + } + +} diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php index aa9236174e3..08f258456db 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php @@ -106,8 +106,48 @@ class MigrateFieldOptionTranslationTest extends MigrateDrupal7TestBase { ]; $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values')); + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_boolean'); + $this->assertNull($config_translation->get('settings.allowed_values')); + + $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_boolean'); + $allowed_values = [ + 0 => [ + 0 => 'Off', + 1 => '1', + ], + 1 => [ + 0 => 'Off', + 1 => '1', + ], + ]; + $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values')); + + $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_checkbox'); + $allowed_values = [ + 0 => [ + 0 => 'Stop', + 1 => 'Go', + ], + 1 => [ + 0 => 'Stop', + 1 => 'Go', + ], + ]; + $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values')); + $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_checkbox'); + $allowed_values = [ + 0 => [ + 0 => 'Stop', + 1 => 'Go', + ], + 1 => [ + 0 => 'Stop', + 1 => 'Go', + ], + ]; + $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values')); // Ensure that the count query works as expected. - $this->assertCount(16, $this->getMigration('d7_field_option_translation')->getSourcePlugin()); + $this->assertCount(20, $this->getMigration('d7_field_option_translation')->getSourcePlugin()); } } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 0a56caeeffe..79374bd2772 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -4617,6 +4617,21 @@ $connection->insert('field_config') 'translatable' => '0', 'deleted' => '0', )) +->values(array( + 'id' => '61', + 'field_name' => 'field_checkbox', + 'type' => 'list_boolean', + 'module' => 'list', + 'active' => '1', + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => '1', + 'locked' => '0', + 'data' => 'a:7:{s:12:"translatable";i:0;s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:14:"allowed_values";a:2:{i:0;s:4:"Stop";i:1;s:2:"Go";}s:23:"allowed_values_function";s:0:"";s:23:"entity_translation_sync";b:0;}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:25:"field_data_field_checkbox";a:1:{s:5:"value";s:20:"field_checkbox_value";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:29:"field_revision_field_checkbox";a:1:{s:5:"value";s:20:"field_checkbox_value";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:1:{s:5:"value";a:1:{i:0;s:5:"value";}}s:2:"id";s:2:"53";}', + 'cardinality' => '1', + 'translatable' => '0', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_config_instance', array( 'fields' => array( @@ -5477,6 +5492,15 @@ $connection->insert('field_config_instance') 'data' => 'a:6:{s:5:"label";s:9:"image_miw";s:6:"widget";a:5:{s:6:"weight";s:2:"18";s:4:"type";s:9:"image_miw";s:6:"module";s:29:"multiupload_imagefield_widget";s:6:"active";i:1;s:8:"settings";a:2:{s:18:"progress_indicator";s:8:"throbber";s:19:"preview_image_style";s:9:"thumbnail";}}s:8:"settings";a:10:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:16:"png gif jpg jpeg";s:12:"max_filesize";s:0:"";s:14:"max_resolution";s:0:"";s:14:"min_resolution";s:0:"";s:9:"alt_field";i:0;s:11:"title_field";i:0;s:13:"default_image";i:0;s:18:"user_register_form";b:0;s:23:"entity_translation_sync";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:5:"image";s:8:"settings";a:2:{s:11:"image_style";s:0:"";s:10:"image_link";s:0:"";}s:6:"module";s:5:"image";s:6:"weight";i:16;}}s:8:"required";i:0;s:11:"description";s:0:"";}', 'deleted' => '0', )) +->values(array( + 'id' => '93', + 'field_id' => '61', + 'field_name' => 'field_checkbox', + 'entity_type' => 'node', + 'bundle' => 'article', + 'data' => 'a:7:{s:5:"label";s:8:"checkbox";s:6:"widget";a:5:{s:6:"weight";s:2:"25";s:4:"type";s:15:"options_buttons";s:6:"module";s:7:"options";s:6:"active";i:1;s:8:"settings";a:0:{}}s:8:"settings";a:2:{s:18:"user_register_form";b:0;s:23:"entity_translation_sync";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"list_default";s:8:"settings";a:0:{}s:6:"module";s:4:"list";s:6:"weight";i:25;}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_data_body', array( 'fields' => array( @@ -5634,6 +5658,88 @@ $connection->insert('field_data_body') 'body_format' => 'filtered_html', )) ->execute(); +$connection->schema()->createTable('field_data_field_checkbox', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'tiny', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_checkbox_value' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + ), + ), + 'primary key' => array( + 'entity_type', + 'entity_id', + 'deleted', + 'delta', + 'language', + ), + 'indexes' => array( + 'entity_type' => array( + 'entity_type', + ), + 'bundle' => array( + 'bundle', + ), + 'deleted' => array( + 'deleted', + ), + 'entity_id' => array( + 'entity_id', + ), + 'revision_id' => array( + 'revision_id', + ), + 'language' => array( + 'language', + ), + 'field_checkbox_value' => array( + 'field_checkbox_value', + ), + ), + 'mysql_character_set' => 'utf8', + )); $connection->schema()->createTable('field_data_comment_body', array( 'fields' => array( 'entity_type' => array( @@ -12047,6 +12153,90 @@ $connection->insert('field_revision_body') 'body_format' => 'filtered_html', )) ->execute(); +$connection->schema()->createTable('field_revision_field_checkbox', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'tiny', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_checkbox_value' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + ), + ), + 'primary key' => array( + 'entity_type', + 'entity_id', + 'revision_id', + 'deleted', + 'delta', + 'language', + ), + 'indexes' => array( + 'entity_type' => array( + 'entity_type', + ), + 'bundle' => array( + 'bundle', + ), + 'deleted' => array( + 'deleted', + ), + 'entity_id' => array( + 'entity_id', + ), + 'revision_id' => array( + 'revision_id', + ), + 'language' => array( + 'language', + ), + 'field_checkbox_value' => array( + 'field_checkbox_value', + ), + ), + 'mysql_character_set' => 'utf8', +)); + $connection->schema()->createTable('field_revision_comment_body', array( 'fields' => array( 'entity_type' => array( @@ -20920,6 +21110,26 @@ $connection->insert('i18n_string') 'objectindex' => '467', 'format' => '', )) +->values(array( + 'lid' => '805', + 'textgroup' => 'field', + 'context' => 'field_checkbox:#allowed_values:0', + 'objectid' => '#allowed_values', + 'type' => 'field_checkbox', + 'property' => '0', + 'objectindex' => '0', + 'format' => '', +)) +->values(array( + 'lid' => '806', + 'textgroup' => 'field', + 'context' => 'field_checkbox:#allowed_values:1', + 'objectid' => '#allowed_values', + 'type' => 'field_checkbox', + 'property' => '1', + 'objectindex' => '0', + 'format' => '', +)) ->execute(); $connection->schema()->createTable('i18n_translation_set', array( 'fields' => array( @@ -22560,6 +22770,38 @@ $connection->insert('locales_target') 'plural' => '0', 'i18n_status' => '0', )) +->values(array( + 'lid' => '805', + 'translation' => 'is - Stop', + 'language' => 'is', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) +->values(array( + 'lid' => '806', + 'translation' => 'is - Go', + 'language' => 'is', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) +->values(array( + 'lid' => '805', + 'translation' => 'fr - Stop', + 'language' => 'fr', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) +->values(array( + 'lid' => '806', + 'translation' => 'Go', + 'language' => 'fr', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) ->execute(); $connection->schema()->createTable('menu_custom', array( 'fields' => array( diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php index 667ecd5975c..584dc635cb0 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php @@ -83,8 +83,8 @@ class Upgrade7Test extends MigrateUpgradeExecuteTestBase { 'contact_form' => 3, 'contact_message' => 0, 'editor' => 2, - 'field_config' => 89, - 'field_storage_config' => 68, + 'field_config' => 90, + 'field_storage_config' => 69, 'file' => 3, 'filter_format' => 7, 'image_style' => 7,