Here I attached a patch to fix the issue to migrate multiple entity reference fields using the migrate support module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pakmanlh’s picture

rodrigoaguilera’s picture

Status: Needs review » Reviewed & tested by the community

Works as expected

amitaibu’s picture

This looks good - just minor comment:

+++ b/entityreference.migrate.inc
@@ -24,4 +27,24 @@ class MigrateEntityReferenceFieldHandler extends MigrateSimpleFieldHandler {
+   * Prepare function.

Can you add a comment on what we are doing here.

rodrigoaguilera’s picture

Assigned: Unassigned » rodrigoaguilera
Status: Reviewed & tested by the community » Needs review
FileSize
2.04 KB

I added some comments and simplified the code before the final return of the prepare function.

amitaibu’s picture

Status: Needs review » Fixed

Merged, thanks!

Status: Fixed » Closed (fixed)

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

saltednut’s picture

Status: Closed (fixed) » Active

Wait... what? We had been migrating multiple entity reference fields correctly until this was brought in. There's zero explanation what the issue was here.

Previously, we had been doing something like:

$this->addFieldMapping('field_collected', 'episodes')->separator(',')->sourceMigration('EpisodeNodes');

This is no longer functioning. I am now seeing only the first item from the list being added to the entity reference field.

Is there an API update we need to consider? If so, where is that documented?

rodrigoaguilera’s picture

Maybe is related with the language of the field. I'll try to investigate more and reproduce it consistently

mikeryan’s picture

Having a customer reporting this is not working - my first glance at the code had me saying "why is it implementing prepare() when the parent class should handle it?". What exactly was the original case that led to this change?

FluxSauce’s picture

Hi, we're using Migrate 2.7 and Entity reference 7.x-1.x-dev and I'm having the problem as #8. In our case, no language was associated with the field or the referenced node. Removing the prepare method resolved the issue (MigrateSimpleFieldHandler worked). Attaching a patch to revert the change.

FluxSauce’s picture

Status: Active » Needs review
mikeryan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. The parent prepare() works just fine - based on the array manipulation in the original patch here, I'm guessing the original author had a mis-structured value array (an extra array) coming in, the patch seems to have changed things to work with that structure rather than the normal simple array of values.

saltednut’s picture

#11 is essentially a revert of the original patch. I can confirm that prepare() method override is unnecessary for a standard entity reference field.

Has anyone tested this against inline_entity_form? Either with/without the prepare() ?

I believe I remember entity reference migrations not working when using that particular widget on fields. This may be the source of the discrepancy.

das-peter’s picture

Patch works like a charm.

amitaibu’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks.

  • amitaibu committed f322d5d on 7.x-1.x authored by FluxSauce
    Issue #2394725 by rodrigoaguilera, FluxSauce, pakmanlh: Migrate multiple...

Status: Fixed » Closed (fixed)

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

patrick.thurmond@gmail.com’s picture

I am unclear as to how I am supposed to structure the data here. I am passing an array of entity_ids and it is only migrating one of them. Do I instead need to pass in a comma separated list?

Nevermind, I got it to work. Ignore me.

ppavels’s picture

Status: Closed (fixed) » Needs review
FileSize
1.75 KB

Re open the issue. I'm attaching a patch for review.

gettysburger’s picture

Where does this stand? I need to migrate multi-value taxonomy terms and am looking for a fix. Thanks.

David Hernández’s picture

Status: Needs review » Reviewed & tested by the community

The patch at #20 seems to be working fine. Marking this issue as RTBC.

yonailo’s picture

There is no need for a new patch, the issue has been closed and multiple entity reference fields can already be imported, see comment in #8 for the proper way to do.

Those trying to push a new patch, can please explain with an example where the issue is ?

minorOffense’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

I'm closing this. I've run a lot of migrations with referenced entities and it works fine. If you run into an issue please create a new issue with details on exactly what's not working.