Support translated content

Created on 9 April 2020, over 4 years ago
Updated 20 August 2024, 3 months ago

I am using this module for some migrations from an existing d8 site to a new one, which as I understand it means that I can't use the core d8 source plugins. It looks like the version of the ContentEntity source that was [ported into core]( https://www.drupal.org/project/drupal/issues/2935951 β†’ ) gained support for translated entities along the way, but we don't have that in this module as yet.

I'm not convinced this patch is complete, but it seems to work for my case, so I wanted to post it here for review. My knowledge of the migration system is still rudimentary I'm afraid, so I don't know that I can write tests for this, but I'm happy to help with further testing or take direction on how to approach this patch differently.

I cobbled this together based on [comment #7]( https://www.drupal.org/project/drupal/issues/2935951#comment-12416520 β†’ ) on the core issue, which had an initial patch adding translation support but before the core ContentEntity class was moved to be a subclass of ContainerFactoryPluginInterface instead of SQLBase. I basically followed that patch but found I needed to add one more condition to the query() method in order to make it work.

This looks for a `langcode` config parameter in the `source` definition, and uses that to pick up source fields based on their langcode.

πŸ› Bug report
Status

Needs review

Version

1.2

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada spiderman Halifax, NS

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 8
    last update 8 months ago
    1 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 8
    last update 8 months ago
    1 pass
  • πŸ‡ΊπŸ‡ΈUnited States majorrobot

    Thanks for all your work on this @spiderman and @DieterHolvoet. I was able to get this to work with nodes with translations.

    For those attempting this kind of migration, there were two things that were not obvious to me, but completely necessary. (It may be like this in non-drupal8 translation migrations, too -- I just don't know/)

    1. Create a migration for the first language and then a migration (which will be very similar) for any other language you want to import. Make sure you have translations: true in the source and destination portions of the non-original-language migrations.
    2. When migrating the non-original language(s), you'll need to use a migration_lookup in the process section to set the nid of the translated nodes. (The original and all translations of a node share the same nid.)

    An example, migrating a "resource" content type with translation to a second language:

    id: my_migration_en
    label: my_migration_en
    migration_tags:
      - Drupal 8
      - resources
    source:
      plugin: d8_entity
      key: migrate
      entity_type: node
      bundle: resource
    process:
      title: title
      body: body
      status: status
      langcode: langcode
      bundle: 'resource'
    destination:
      plugin: entity:node
      default_bundle: resource
    
    id: my_migration_es
    label: my_migration_es
    migration_tags:
      - Drupal 8
      - resources
    source:
      plugin: d8_entity
      key: migrate
      entity_type: node
      bundle: resource
      translations: true
    process:
      title: title
      body: body
      status: status
      bundle: 'resource'
      langcode: langcode
      nid:
        plugin: migration_lookup
        migration:  my_migration_en
        source: nid
    destination:
      plugin: entity:node
      default_bundle: resource
      translations: true
      nid: nid
    

    I've set this issue to Needs Review to see if the fix will move along.

  • First commit to issue fork.
  • Status changed to Needs work 4 months ago
  • heddn Nicaragua

    We're seeing test failures again.

  • Pipeline finished with Failed
    4 months ago
    Total: 134s
    #229336
  • Pipeline finished with Failed
    4 months ago
    Total: 138s
    #231504
  • πŸ‡ΊπŸ‡ΈUnited States majorrobot

    I took a peek at the failing tests -- looks like there's one main PHPUnit failure. I rebased on most recent 8.x-1.x-dev and cleaned up a few of phpcs's complaints. I don't have a deep familiarity with the module, so am still digging into the unit test issue.

  • Status changed to Needs review 4 months ago
  • πŸ‡¨πŸ‡¦Canada wilco

    I have been trying to use this patch for the latest build 1.2.0 to no avail. This is my response to that...

  • πŸ‡¨πŸ‡¦Canada wilco
  • πŸ‡·πŸ‡΄Romania bbu23

    Adding a new patch created from previous version's applied patch, rebased with the new version.
    Reason: the MR does not apply as confirmed by @wilco, but although the patch in #22 does apply, the migration throws an error when I try to import it.

Production build 0.71.5 2024