Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here I attached a patch to fix the issue to migrate multiple entity reference fields using the migrate support module.
Comment | File | Size | Author |
---|---|---|---|
#20 | migrate_multiple_entity_reference-2394725-20.patch | 1.75 KB | ppavels |
| |||
#11 | migrate_multiple_entity_reference-2394725-10.patch | 1.89 KB | FluxSauce |
Comments
Comment #1
pakmanlhComment #2
rodrigoaguileraWorks as expected
Comment #3
amitaibuThis looks good - just minor comment:
Can you add a comment on what we are doing here.
Comment #4
rodrigoaguileraI added some comments and simplified the code before the final return of the prepare function.
Comment #5
amitaibuMerged, thanks!
Comment #8
saltednutWait... 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?
Comment #9
rodrigoaguileraMaybe is related with the language of the field. I'll try to investigate more and reproduce it consistently
Comment #10
mikeryanHaving 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?
Comment #11
FluxSauce CreditAttribution: FluxSauce commentedHi, 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.Comment #12
FluxSauce CreditAttribution: FluxSauce commentedComment #13
mikeryanLooks 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.
Comment #14
saltednut#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.
Comment #15
das-peter CreditAttribution: das-peter at Cando commentedPatch works like a charm.
Comment #16
amitaibuMerged, thanks.
Comment #19
patrick.thurmond@gmail.comI 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.
Comment #20
ppavels CreditAttribution: ppavels commentedRe open the issue. I'm attaching a patch for review.
Comment #21
gettysburger CreditAttribution: gettysburger commentedWhere does this stand? I need to migrate multi-value taxonomy terms and am looking for a fix. Thanks.
Comment #22
David Hernández CreditAttribution: David Hernández at Gizra commentedThe patch at #20 seems to be working fine. Marking this issue as RTBC.
Comment #23
yonailo CreditAttribution: yonailo as a volunteer commentedThere 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 ?
Comment #24
minorOffense CreditAttribution: minorOffense at Coldfront Labs Inc. commentedI'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.