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.
We are developing some sites that allow for importing nodes from one to the another using Feeds. Many of our custom content types will have entity reference fields. I've done a lot of reading and I think I have a good understanding of how I can import and map reference fields from source to target.
Is it possible to have referenced entities imported when the referencing nodes are imported? (maybe with some type of trigger(s) or a Feeds plugin or...?)
Thank you!
Comment | File | Size | Author |
---|---|---|---|
#12 | create-referenced-entities-on-import-1839588-12-D7.patch | 2.61 KB | anweshasinha |
|
Comments
Comment #1
alisonComment #2
MegaChriz CreditAttribution: MegaChriz commentedA feature like this seems to be planned for the Feeds entity reference module.
Comment #3
colanAs per #1875848: doesnt work, it looks like that module filled the hole that is now satisfied by #1616680: Handle more mapping keys in Feeds integration so it is no longer necessary. It does not appear to create referenced entities.
I'd like to see taxonomy terms created when I'm importing term reference fields as strings with the mapping Entity reference by Entity label. If the term doesn't exist yet (i.e. no match for the label), a new term would be created. This would be better than these error messages:
Moving to the ER queue as Feeds support for this sort of thing should be handled in there.
Comment #4
colanLooks like Entityreference Autocreate may do the trick for now.
Comment #5
anweshasinha CreditAttribution: anweshasinha at Novatree commentedI have created a patch on entityreference module which will create referenced entities using a Feeds importer of the referenced entity.
This works in the following way:
1. Suppose you have 4 entities A,B and C. Entity A has a field A which refers to Entity B, and Entity B has a field B which refers to Entity C.
2. Create importers for all the entities – first C, then B and then A. In mapping page of importer for entity B, you need to select the target as "(Entity reference by Entity label - with import) (field_hotel:importer:hotel_importer)" as show in the attached screenshot. Similarly create mapping for entity A.
3. Create a single CSV with columns from all three importers and upload it against importer of Entity.
4. When entities of type A are imported, entities of types B and C also get created on the fly.
Comment #6
anweshasinha CreditAttribution: anweshasinha at Novatree commentedComment #7
anweshasinha CreditAttribution: anweshasinha at Novatree commentedRevised patch to make it work for User Entities
Comment #8
anweshasinha CreditAttribution: anweshasinha at Novatree commentedSorry wrong patch, resubmitting!
Comment #12
anweshasinha CreditAttribution: anweshasinha at Novatree commentedPatch resubmitted. Now working in entityreference 7.x-1.x-dev
Comment #13
anweshasinha CreditAttribution: anweshasinha at Novatree commentedComment #14
FireHawkX CreditAttribution: FireHawkX commentedIf only I had known this existed before! (been wasting so many hours trying to fix a problem)
First, the patch applied without issue to latest version.
However, on 1 of my 12 feeds importer, when I open the page "mapping for node processor page" (or tamper)
I get a couple hundreds of the following error :
Warning: in_array() expects parameter 2 to be array, null given in entityreference_feeds_processor_targets_alter() (line 57 of ...\sites\all\modules\entityreference\entityreference.feeds.inc).
EDIT :
Seems like my test was poorly done, I thought it worked, but after more analyse, only the fields set to "terms reference" actually created new taxonomy terms... the entity reference did not create the terms sadly :(
I did another test with a brand new feeds importer with only 2 fields in there... both entity references... and i got 242 errors of "term not found" and no terms got created
Note that by reverting to previous version, all the warnings stopped appearing
Let me know if you desire me to provide more info, or do additional testing
Finally, for anyone checking here for a workaround/solution, I created a couple of new feeds importer that only imported the new data directly into their respective taxonomy... then I was able to link them using "Query finder" during my import of the actual nodes using Entity References instead of Terms reference since they already existed!
Comment #15
Mile3 CreditAttribution: Mile3 commentedCurious if anyone has been able to get this to work on D8/9?