Problem/Motivation

In #2225717: Add config translation support to migrations and implement for Drupal 6 user profile fields we set up a system to migrate config translations. We also migrated translations for user profile fields and their descriptions. We did not migrate field options (eg. select boxes or radio buttons or checkboxes) translations.

While working on the patch and creating the test fixture, in particular, it was discovered that only the select fields can have value translations. Therefor, this is limited to select fields.

Proposed resolution

Migrate user profile field options translations.

Remaining tasks

  1. Add data to test fixture . See generating database fixtures for d8 migrate tests
  2. Write the migration test
  3. Write a source plugin and source plugin test
  4. Write the migration

.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#56 interdiff-52-56.txt1.64 KBquietone
#56 2845975.patch16.27 KBquietone
#52 interdiff-50-52.txt675 bytesquietone
#52 2845975-52.patch16.4 KBquietone
#50 interdiff-48-50.txt597 bytesquietone
#50 2845975-50.patch16.41 KBquietone
#48 2845975-48.patch16.4 KBquietone
#43 interdiff-41-43.patch3.24 KBquietone
#43 2845975-43.patch15.7 KBquietone
#41 interdiff-38-41.txt630 bytesquietone
#41 2845975-41.patch14.45 KBquietone
#38 interdiff.txt588 bytesquietone
#38 2845975-38.patch14.49 KBquietone
#35 interdiff-33-35.txt1.14 KBquietone
#35 2845975-35.patch14.78 KBquietone
#33 interdiff-32-33.txt2.35 KBquietone
#33 2845975-33.patch14.29 KBquietone
#32 2845975-32.patch14.38 KBquietone
#29 interdiff-27-29.txt731 bytesquietone
#29 2845975-29.patch13.85 KBquietone
#27 2845975-27.patch13.13 KBquietone
#27 interdiff-25.27.txt30.63 KBquietone
#25 interdiff-24-25.txt4.6 KBquietone
#25 2845975-25.patch39.82 KBquietone
#24 2845975-24.patch38.96 KBjofitz
#24 interdiff-2845975-22-24.txt2.13 KBjofitz
#22 2845975-22.patch39 KBjofitz
#19 28459755-19.patch0 bytesaleevas
#14 2845975-14.patch39.01 KBquietone
#12 2845975-12.patch8.92 KBquietone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy created an issue. See original summary.

Gábor Hojtsy’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

mikeryan’s picture

Status: Needs work » Active
rakesh.gectcr’s picture

Assigned: Unassigned » rakesh.gectcr

Still not clear on, what will be the first approach here. Working on it. Any guidance will help

Gábor Hojtsy’s picture

I think this would use the regular config translation migrations, see migrations for vocabularies, user profile fields themselves, etc. The most recent one is #2225781: Migrate D6 i18n taxonomy vocabularies.

quietone’s picture

Issue summary: View changes

@rakesh.gectcr, thanks for taking this on.

AFAIKT, the d6 test fixture does not include a user profile select field. So the first steps are to add the data to the fixture and add the test. There is a handbook page for generating database fixtures for d8 migrate tests. As usual, please improve that page, it is pretty basic. For the test, the direction provided in #7 looks good. This will need a new source plugin, so that and it's test would be next. Then the migration itself.

I worked on the test fixture a bit. I added a select field to the user profile. But I can't find where/how to translate it. The new field doesn't even appear on the Translate interface and I'm not sure how to translate the select values. Can someone explain these steps?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Status: Active » Needs work
FileSize
8.92 KB

Here is a start. This doesn't include the changes to the fixture because I don't have time to clean it up now. So, there is no point in running the tests until that is done.

This will also need to be postponed on #2961114: Migrate D6 i18n CCK field option translations because I'm sure it needs the destination changes but I am setting to NW until I add the changes to the test fixture.

quietone’s picture

Assigned: rakesh.gectcr » Unassigned

Meant to unassign rakesh.gectcr, it has been over a year.

quietone’s picture

Issue summary: View changes
Status: Needs work » Postponed
FileSize
39.01 KB

Add in the changed to the test fixture.

Now postponing until #2961114: Migrate D6 i18n CCK field option translations is committed.

masipila’s picture

quietone’s picture

Status: Postponed » Needs review

No longer postponed. Testing patch in #14.

Status: Needs review » Needs work

The last submitted patch, 14: 2845975-14.patch, failed testing. View results

quietone’s picture

Issue tags: +Needs reroll

Not surprised that it needs a reroll.

aleevas’s picture

Status: Needs review » Needs work

The last submitted patch, 19: 28459755-19.patch, failed testing. View results

quietone’s picture

@aleevas, wrong patch?

jofitz’s picture

Status: Needs work » Needs review
FileSize
39 KB

Re-rolled.

Status: Needs review » Needs work

The last submitted patch, 22: 2845975-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jofitz’s picture

Fixed coding standards errors.

Leaving as Needs Work to fix test failures.

quietone’s picture

Status: Needs work » Needs review
FileSize
39.82 KB
4.6 KB

This took a while. I think there were errors in patch #14 which wasn't helping at all.

  • Changed the logic in the new process plugin to return NULL when there is no translation.
  • Changed the name of the profile field for count of trees from profile_ to profile_count_trees this seems to have been lost betweem #12 and #14 (I think). Either way it is fixed now.
  • Added an option that should be in the fixture.
  • Added tests for the other option fields that are translated

Now, lets see if that fixes everything.

Status: Needs review » Needs work

The last submitted patch, 25: 2845975-25.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
30.63 KB
13.13 KB

Added a conditional to the source plugin, d6_profile_field_translation, because the test fixture introduces a profile field that has does not have a translation for the title but does for this options. This meant the query was returning a row where language was NULL.
Took out a lot of changes in the test fixture which are not needed. At least I hope not.
And fixed the translation values, it should not have a value of 30.

Status: Needs review » Needs work

The last submitted patch, 27: 2845975-27.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
13.85 KB
731 bytes

Fix formatting in yml file and update the entity counts.

quietone’s picture

This is now ready for review. Thanks!

maxocub’s picture

Status: Needs review » Needs work

As always, great work with those tricky i18n issues.

  1. +++ b/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml
    @@ -0,0 +1,59 @@
    +    allowed_values: settings
    

    Unused constant.

  2. +++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,47 @@
    +  /**
    +   * {@inheritdoc}
    +   *
    +   * Get the field default/mapped settings.
    +   */
    

    According to https://www.drupal.org/docs/develop/standards/api-documentation-and-comm..., {@inheritdoc} should be the only line in the docblock.

  3. +++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,47 @@
    +
    +        default:
    

    Do we need this empty default clause?

  4. +++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,63 @@
    +
    +    $res = $query->execute()->fetchAll();
    

    This can be removed.

quietone’s picture

Status: Needs work » Needs review
FileSize
14.38 KB

First a reroll.

quietone’s picture

And fixes for all the items in #31.

The last submitted patch, 32: 2845975-32.patch, failed testing. View results

quietone’s picture

Messed up the test fixture in the reroll. This should fix it.

The last submitted patch, 33: 2845975-33.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 35: 2845975-35.patch, failed testing. View results

quietone’s picture

I really dislike rerolling the test fixtures.

Maybe this will fix it.

quietone’s picture

Finally, test are passing again! Everything in #31 has been addressed so this is ready for review again,

maxocub’s picture

Status: Needs review » Needs work

The patch looks quite ready, but I still have two questions and one nit :

  1. +++ b/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml
    @@ -0,0 +1,58 @@
    +  type:
    +    plugin: static_map
    +    source: type
    +    map:
    +      checkbox: boolean
    +      date: datetime
    +      list: text
    +      selection: list_string
    +      textfield: text
    +      textarea: text_long
    +      url: link
    +  results:
    +    plugin: d6_profile_field_option_translation
    +    source:
    +      - '@type'
    +      - translation
    
    +++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,46 @@
    +      switch ($field_type) {
    +        case 'list_string':
    +        case 'list_integer':
    +        case 'list_float':
    +          foreach ($list as $key => $value) {
    +            $allowed_values[] = ['label' => $value];
    +          }
    +          break;
    +
    +      }
    

    Because there's no "bypass: true", the values in the "static_map" process plugin are the only field types that can be passed to the "d6_profile_field_option_translation" process plugin. And in the switch statement of this last process plugin, we have cases for "list_string", "list_integer" & "list_float", but no default case. This makes me think that either there is some some missing values in the "static_map" (list_integer & list_float) and some extra ones too (anything that's not list_*) or either we need a default case in the switch statement.

    Since this patch is dealing with option fields, I think the possible values in the static map should only be list_* fields, but maybe I'm missing something...

  2. +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
    @@ -27764,30 +27794,6 @@
    -  'lid' => '1672',
    -  'translation' => 'fr - Type',
    -  'language' => 'fr',
    -  'plid' => '0',
    -  'plural' => '0',
    -  'i18n_status' => '0',
    -))
    -->values(array(
    -  'lid' => '1692',
    -  'translation' => 'fr - Talos IV',
    -  'language' => 'fr',
    -  'plid' => '0',
    -  'plural' => '0',
    -  'i18n_status' => '0',
    -))
    -->values(array(
    -  'lid' => '1694',
    -  'translation' => 'fr - The home of Captain Christopher Pike.',
    -  'language' => 'fr',
    -  'plid' => '0',
    -  'plural' => '0',
    -  'i18n_status' => '0',
    -))
    -->values(array(
    

    Are those lines removed for a reason or by accident? I can't figure out why they would need (or not) to get removed.

  3. +++ b/core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/ProfileFieldOptionTranslationTest.php
    @@ -0,0 +1,73 @@
    +    $test[0]['expected_data'] = [];
    

    Nit: This line can be removed.

quietone’s picture

Status: Needs work » Needs review
FileSize
14.45 KB
630 bytes

Just fixing the nit now (time to listen to the DrupalSouth session!).

quietone’s picture

Status: Needs review » Needs work

40.1. That static_map is copied (like most of that migration) from user_profile_field.yml. Having said that, I think (maybe) the source plugin should extend from ProfileField.

40.2. To fix this the following needs to be restored to the fixture, which will be easier when #3016011: Reroll all migrate dump files is committed.

- 'lid' => '1672',
- 'translation' => 'fr - Type',
- 'language' => 'fr',
- 'plid' => '0',
- 'plural' => '0',
- 'i18n_status' => '0',
-))

quietone’s picture

Status: Needs work » Needs review
FileSize
15.7 KB
3.24 KB

40.1 Removed unused items from static map as suggested. Also, changed the source plugin to extend from ProfileField.
40.2 Restored the accidentally removed block from the test fixture.

Status: Needs review » Needs work

The last submitted patch, 43: interdiff-41-43.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review

The NW is because I named the interdiff a patch (again). This is really ready for review, all the points raised in #40 have been addressed.

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
heddn’s picture

Issue tags: +Migrate critical

Triaging the issue queue.

quietone’s picture

Status: Needs work » Needs review
FileSize
16.4 KB

This is the reroll.

vacho’s picture

Issue tags: -Needs reroll

Actual patch can apply.

quietone’s picture

This needed a reroll.

Status: Needs review » Needs work

The last submitted patch, 50: 2845975-50.patch, failed testing. View results

quietone’s picture

Arg, a stupid typo.

quietone’s picture

Status: Needs work » Needs review

NR for testbot

quietone’s picture

Issue summary: View changes

Remove postpone from the IS.

This is ready for review.

maxocub’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

I tested the patch manually and it worked as expected, the option translations from the Profile select fields were migrated properly.

But, the IS should be updated because it is misleading. It says that radio button and checkbox field translation should be migrated too in this issue, but they are not. I've checked on Drupal 6 what type of fields needs their option translation migrated and it seem that it is only the select boxes, as this patch does.

As for the code :

  1. +++ b/core/modules/config_translation/migrations/d6_profile_field_option_translation.yml
    @@ -0,0 +1,52 @@
    +  type:
    +    plugin: static_map
    +    source: type
    +    map:
    +      selection: list_string
    
    +++ b/core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,46 @@
    +      switch ($field_type) {
    +        case 'list_string':
    +        case 'list_integer':
    +        case 'list_float':
    +          foreach ($list as $key => $value) {
    +            $allowed_values[] = ['label' => $value];
    +          }
    +          break;
    +
    +      }
    

    I'm still bugging over this static map and switch statement mismatch. The only field type that we need is the list_string, as we already have in the static map. So, we should not need the switch statement for list_integer and list_float, I think a simple if statement that checks if the field type is list_string should be enough.

  2. +++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldOptionTranslation.php
    @@ -0,0 +1,62 @@
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +
    

    A lonely @inheritdoc that has lost its method...

quietone’s picture

Status: Needs work » Needs review
FileSize
16.27 KB
1.64 KB

Fixes for #55.1 and #55.2. Still need to update the IS>

quietone’s picture

Issue summary: View changes

Updated IS and tried to keep some of the history.

quietone’s picture

@maxocub thanks for the review!

maxocub’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

All feedbacks are addressed. Manual and automated tests are positive. IS has been updated. Let's RTBC this.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 56: 2845975.patch, failed testing. View results

quietone’s picture

Failure looked unrelated, so retesting

quietone’s picture

Status: Needs work » Reviewed & tested by the community

Tests passing again. There has been no changes to the patch since the RTBC so I am restoring the RTBC.

catch’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 75a4213161 to 8.7.x and cdd317ebc6 to 8.6.x. Thanks!

  • catch committed 75a4213 on 8.7.x
    Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor...

  • catch committed cdd317e on 8.6.x
    Issue #2845975 by quietone, Jo Fitzgerald, aleevas, maxocub, Gábor...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.