Migrate translated entity reference from D7 to D8

Created on 14 February 2017, almost 8 years ago
Updated 3 July 2024, 6 months ago

Problem/Motivation

When migrating entity reference fields from a multilingual D7 site to a multilingual D8 site, I get the following error:

"Value is not a valid entity." line 106 on core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php

This happens because core expects the entity reference value expects either a scalar value(like an ID) or an object typed as EntityInterface and the migration is sending it an array with ID and langcode.

Proposed resolution

I imagine one solution would be to allow sending both ID and langcode as parameters for an entity load, but I'm not sure how that would work exactly. I have a workaround for now that I'll describe in detail on the comments bellow.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated 3 days ago

Created by

πŸ‡¨πŸ‡¦Canada jmoreira

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States majorrobot

    If I am wrong, reopen this issue by setting the status to Active and explain what is not working, what error message you are getting and anything you think is relevant.

    Ack, I hate to reopen this issue, but I think it is warranted. If I should not, let me know! I'm having the same experience as OP, as well as @Shiraz Dindar above.

    I'm running Drupal 10.2.5 and I'm migrating from another site on 10.2.5. Though I'm using the migrate_drupal_d8 contrib module, it still calls the core Migration Lookup plugin. In my case, I have an image field migrating to an identical image field. Both sites have Content Translation enabled for the content type. It does not seem to matter, but I have the image field configured not to be translatable.

    #2912348: Handle entity_references related to Drupal 6 and 7 node translations with different IDs has some similarities, but I think it is actually a different issue.

    I understand that issue to solve a problem where entity reference migrations aren't looking up the correct original target_ids. The issue here is that entity references end up with 2 destination ids: the target_id and the langcode. The target_id is correct. However, EntityReference->setValue() only accepts a single scalar value.

    Thus, I'm still getting
    "Value is not a valid entity." line 106 on core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php

    The patch in #13 πŸ› Migrate translated entity reference from D7 to D8 Needs review solves the issue for me, too. The solution in the patch seems a bit heavy-handed, but I don't know other use cases well enough to say whether or not the patch would break other migrations. It seems a bit dangerous, but I can't say for sure:

         if ($destination_ids) {
    -      if (count($destination_ids) == 1) {
    +      if (count($destination_ids) >= 1) {
             return reset($destination_ids);
           }
           else {
    
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot β†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request β†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    This needs to be fixed on 11.x (our main development branch) first, and are then back ported as needed according to our policies. Also, 10.2 is in security mode now.

    Thanks for the extra information in #21. That seems useful. We do need a test here to demonstrate the problem.

Production build 0.71.5 2024