Problem/Motivation

The d7_user.yml migration template migrates the language field even if it is empty, i.e.:

...
process:
  ...
  langcode: language
  preferred_langcode: language
  preferred_admin_langcode: language
  ...

As a result custom user fields (which do have a language) are not displayed correctly.

Proposed resolution

On my site the default langcode is en so I have used a hook_migration_create() to make the required change:

  if ($migration->id() == 'd7_user') {
    $process = $migration->getProcess();
    $process['langcode'] = array(
      'plugin' => 'default_value',
      'source' => 'language',
      'default_value' => 'en',
    );
    $process['preferred_langcode'] = array(
      'plugin' => 'default_value',
      'source' => 'language',
      'default_value' => 'en',
    );
    $process['preferred_admin_langcode'] = array(
      'plugin' => 'default_value',
      'source' => 'language',
      'default_value' => 'en',
    );
    $migration->setProcess($process);
  }

This is equivalent to make the following changes to the d7_user.yml migration template:

...
process:
  ...
  langcode:
    plugin: default_value
    source: language
    default_value: en
  preferred_langcode:
    plugin: default_value
    source: language
    default_value: en
  preferred_admin_langcode:
    plugin: default_value
    source: language
    default_value: en
  ...

I suggest a general version of this is required, using the default_langcode of the site as the default value for these three fields. I suspect this will require a custom MigrateProcessPlugin (unless it is possible to pass system.site.default_langcode into the default_value MigrateProcessPlugin).

Remaining tasks

Decide how to solve this
Solve it!

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jo Fitzgerald created an issue. See original summary.

jofitz’s picture

As proposed, I have written a custom MigrateProcessPlugin that fills missing fields with a value from configuration (in this case system.site / default_langcode). Here is the patch.

Status: Needs review » Needs work

The last submitted patch, 2: core-migrate_d7_users_without_language-2671312-2.patch, failed testing.

jofitz’s picture

The user langcode field should not be empty because it is required to display user fields (which have a langcode by default).

jofitz’s picture

quietone’s picture

Issue tags: +migrate-d7-d8

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Updated for v8.1.1.

jofitz’s picture

Version: 8.1.1 » 8.1.x-dev

Version changed in error.

vasi’s picture

I like this approach! It would be great for #2751223: D6 & D7 users are migrated into D8 with incorrect langcode too. Should we test that users can have a langcode in the D7 user table, too?

mikeryan’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I like it too! But, a new generally-useful process plugin like this should have its own tests (including a test of the 'strict' option, which is not tested here in the user scenario). Ideally, actually, adding a new general-purpose plugin should be a separate issue, and the user langcode bug dependent on it, although both the plugin and the application are simple enough I wouldn't insist on it...

jofitz’s picture

Status: Needs work » Postponed

The new migration process plugin has been set up in a separate ticket: #2752281: Add DefaultConfigValue MigrateProcessPlugin. This ticket is now dependent on that and so is postponed for the time-being.

jofitz’s picture

Status: Postponed » Needs review
Issue tags: -Needs tests
FileSize
1.97 KB
2.26 KB

Add test for d7 user *with* a langcode, as suggested by @vasi.

(the status will be returned to "postponed" once this test passes)

Status: Needs review » Needs work

The last submitted patch, 13: core-migrate_d7_users_without_language-2671312-13.patch, failed testing.

jofitz’s picture

Update patch for d8.1.x-dev.

Status: Needs review » Needs work

The last submitted patch, 15: core-migrate_d7_users_without_language-2671312-15.patch, failed testing.

jofitz’s picture

Include in the patch the previously (accidentally) omitted MigrateProcessPlugin.

jofitz’s picture

Status: Needs review » Postponed

Setting back to postponed dependent on #2752281: Add DefaultConfigValue MigrateProcessPlugin.

quietone’s picture

This is really nice.

What about the language for D6 user migrations? Should that be looked at here or in another issue?

Two changes for the fixture.

  • +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
    @@ -40804,6 +40804,24 @@
    +  'mail' => 'admin@local.host',
    

    Please change, this is the same email address as uid 1.

  • +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
    @@ -40804,6 +40804,24 @@
    +  'language' => 'de',
    

    Should be a language installed on the fixture. Currently, English and Icelandic are installed, so please change to 'is'.

  • jofitz’s picture

    jofitz’s picture

    Status: Postponed » Needs review
    FileSize
    1.53 KB
    4.99 KB

    Apply changes requested by @quietone.

    @quietone, can I be cheeky and ask you to review #2752281: Add DefaultConfigValue MigrateProcessPlugin, please, which is currently holding up this ticket. Thanks.

    Status set to "Needs review" to test the patch, but will be returned to "Postponed" once the patch is confirmed.

    jofitz’s picture

    Status: Needs review » Postponed

    Setting back to postponed dependent on #2752281: Add DefaultConfigValue MigrateProcessPlugin.

    quietone’s picture

    Status: Postponed » Needs review

    @Jo Fitzgerald, of course you can.

    Version: 8.1.x-dev » 8.2.x-dev

    Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

    Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

    DamienMcKenna’s picture

    Status: Needs review » Needs work

    The last submitted patch, 25: drupal-n2671312-25.patch, failed testing.

    jofitz’s picture

    Status: Needs work » Postponed

    @DamienMcKenna imo there's not much point in re-rolling this patch until #2752281: Add DefaultConfigValue MigrateProcessPlugin is RTBC.

    Gábor Hojtsy’s picture

    Status: Postponed » Closed (duplicate)

    #2751223: D6 & D7 users are migrated into D8 with incorrect langcode worked on the same problem in Drupal 6 and now in Drupal 7 and devised a slightly different solution where it provides different fallback values based on the invalidity of the source language, dealing with not only the empty case (where instead of the site default language, English should be the fallback), but also the invalid language case, where indeed, the site default language should be the fallback. I think that solution is a lot more complete and while it does not provide or depend on a general fallback solution, its logic is so specific to user languages, that that makes sense.

    It would be nice to take the credits of the issue here and move it over there to be fair with all contributors on this issue, which would require at least the patch posters to comment there too.