0

I have imported two content types. One is for a vendor list and the other is for a contact list. The vendor list was imported with a vendor id column. The contact list was also imported with a vendor id column that indicates which vendor a contact is related to. A vendor also has many contacts.

I have added an entity reference field to the vendor list referencing the contact list but I don't see a way to link the vendor id columns together.

I have also tried to use an entity reference view with a relationship and contextual filter.

The result I get is an empty contact list for each vendor.

I have read many articles and watched several videos but I haven't found one that pertains to my situation.

How do I get these two content types to reference each other via the vendor id? Do I need to go about it a different way? Is there something I am missing when setting up the entity reference?

1 Answer 1

0

You only need to store the vendor ID retrieved from the remote API on the Vendor. Contacts would be linked by an entity reference field, not the remote vendor ID. The logic is as follows:

  1. Create an entity for Vendor (Either a new content type, or a new entity type)
  2. Create an entity type for Contact (Either a new content type, or a new entity type)
  3. Add a field for remote_vendor_id to the Vendor entity. This will hold the value retrieved from the remote API
  4. Add an entity reference field allowing for unlimited values, to the Vendor, referencing the Contact entity you created
  5. Upon import, create the Vendor entity if it does not already exist, and set the value for remote_vendor_id to be the value retrieved from the remote API
  6. For Contacts retrieved from the remote API, load the Vendor entity that has remote_vendor_id set to the vendor ID for the contact, Create a new Contact entity, and add that Contact entity as an entity reference using the field created on the Vendor entity in step 1 above.

This thread can likely help you with the coding for the above: https://www.drupal.org/project/entityreference/issues/1388924

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.