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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alison’s picture

Component: Documentation » Miscellaneous
MegaChriz’s picture

Issue summary: View changes

A feature like this seems to be planned for the Feeds entity reference module.

colan’s picture

Title: Importing referenced entities » Create referenced entities on importing referrers via Feeds
Project: Feeds » Entity reference
Version: 7.x-2.0-alpha7 » 7.x-1.x-dev
Category: Support request » Feature request

As 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:

No existing entity found for entity 0 entityreference to source entity TERM_NAME

Moving to the ER queue as Feeds support for this sort of thing should be handled in there.

colan’s picture

Looks like Entityreference Autocreate may do the trick for now.

anweshasinha’s picture

I 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.

anweshasinha’s picture

Status: Active » Needs review
anweshasinha’s picture

anweshasinha’s picture

The last submitted patch, 5: create-referenced-entities-on-import-1839588-5-D7.patch, failed testing.

The last submitted patch, 7: create-referenced-entities-on-import-1839588-7-D7.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: create-referenced-entities-on-import-1839588-8-D7.patch, failed testing.

anweshasinha’s picture

Patch resubmitted. Now working in entityreference 7.x-1.x-dev

anweshasinha’s picture

Status: Needs work » Needs review
FireHawkX’s picture

If 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!

Mile3’s picture

Curious if anyone has been able to get this to work on D8/9?