I have an entity reference field that has 2 taxonomies being referenced. This makes my CSV import bomb out. Is there a way to tell the plugin entity_lookup/generate that there are two taxonomies in use? Here's my config yml (problem in field_interacting_drug):

id: interactiontest
label: Migrate Detailed Interactions
migration_group: interaction_import
source:
   plugin: csv
   path: import/interaction-test.csv
   header_row_count: 1
   keys:
      - uuid
   delimiter: '|'
   column_names:
     0:
       uuid: uuid
     1:
       arv: arv
     2:
       arv_dose: arv dose
     3:
       arv_effect: arv effect
     4:
       interacting_drug: interacting drug
     5:
       interacting_drug_dose: interacting drug dose
     6:
       interacting_drug_effect: interacting drug effect
     7:
       mechanism: mechanism
destination:
   plugin: entity:node
process:
   type:
    plugin: default_value
    default_value: detailed_interactions
   field_arv_drug:
    plugin: entity_generate
    source: arv
   field_arv_dose: arv_dose
   field_effect_on_arv: arv_effect
   field_interacting_drug:
    plugin: entity_generate
    source: interacting_drug
   field_interacting_drug_dose: interacting_drug_dose
   field_effect_on_interacting_drug: interacting_drug_effect
   field_mechanism: mechanism
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jaysonjaynes created an issue. See original summary.

Ada Hernandez’s picture

Assigned: Unassigned » Ada Hernandez

checking this!

Ada Hernandez’s picture

if you have 2 vocabulary always there's one what is by default to store the new item, so in the migration'll take that, but I tested that and a exception is thrown because in entity_lookup plugin there's a extra reset function, so I removed this and works!

Ada Hernandez’s picture

Assigned: Ada Hernandez » Unassigned
Status: Active » Needs review
jaysonjaynes’s picture

Thank you so much! Hmm...it's not working for me. I'm using entity_generate. Is that the same thing? What does your YML file look like?

jaysonjaynes’s picture

I tried entity_lookup and it didn't work...

id: interactiontest5
label: Migrate Detailed Interactions
migration_group: interaction_import
source:
   plugin: csv
   path: import/interaction-test.csv
   header_row_count: 1
   keys:
      - uuid
   delimiter: '|'
   column_names:
     0:
       uuid: uuid
     1:
       arv: arv
     2:
       arv_dose: arv dose
     3:
       arv_effect: arv effect
     4:
       interacting_drug: interacting drug
     5:
       interacting_drug_dose: interacting drug dose
     6:
       interacting_drug_effect: interacting drug effect
     7:
       mechanism: mechanism
destination:
   plugin: entity:node
process:
   type:
    plugin: default_value
    default_value: detailed_interactions
   field_arv_drug:
    plugin: entity_generate
    source: arv
   field_arv_dose: arv_dose
   field_effect_on_arv: arv_effect
   field_interacting_drug:
    plugin: entity_lookup
    source: interacting_drug
   field_interacting_drug_dose: interacting_drug_dose
   field_effect_on_interacting_drug: interacting_drug_effect
   field_mechanism: mechanism
Ada Hernandez’s picture

@jaysonjaynes, you can check this blog, maybe it can help you with your migrations template, ...: https://www.mtech-llc.com/blog/ada-hernandez/how-migrate-images-drupal-8... and https://www.mtech-llc.com/blog/ada-hernandez/entity-lookup-generate-migr...

jaysonjaynes’s picture

Thanks, @adita! I've seen those and will review them again.

heddn’s picture

Category: Support request » Bug report
Status: Needs review » Needs work

Let's add a kernel test for this where the destination field has two term bundles possible for it. Back to NW for tests.

kobb’s picture

So glad this is being discussed. I am running into the same issue. I've tried this:

  field_profile_department:
    -
      plugin: entity_lookup
      entity_type: node
      bundle: department
      source: '@_prepare_dept_titles'
    -
      plugin: entity_lookup
      entity_type: node
      bundle: program
      source: '@_prepare_program_titles'

But it only records the last entity_lookup processed.

EDIT: I realize now my problem is slightly different than the origin of this thread. I have two columns in my CSV that are being migrated into one node reference field with two possible content types. So the hard part is already done before the migration. I just need it to migrate both sets of references into one field.

somersoft’s picture

In my case, Entity Generate was being called with an array for $value and not a single value. The patch iterators over the passed values. It can then cope with all cases where entities are missing or present.

Part of example migration configuration .yml

process:
  field_a:
    -
      plugin: callback
      callable: unserialize
      source: field_a
    -
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle: vocabulary_machine_name
      bundle_key: vid
      value_key: name
badrange’s picture

somersoft: I had a similar issue like you; but with my own custom process plugin. Adding

  /**
   * {@inheritdoc}
   */
  public function multiple() {
    return TRUE;
  }

to my custom plugin resolved this for me. I'm not saying you haven't collided with a bug, I'm just saying that in my case changing my migration process plugin solved it. If you want this fixed, I suggest creating a new issue with your patch.

seth.e.shaw’s picture

@Kobb: did you ever find a solution to doing lookups across multiple content types?

heddn’s picture

Status: Needs work » Fixed

There's sub_process to cope with arrays. And there's the recent SingleValue and MultipleValues that could also help. Still needs work because needs tests.

I'm going to suggest this is fixable with one of those solutions. I'll probably be proved wrong, but let's see if we can cleanup the issue queue.

kobb’s picture

@seth.e.shaw: No. I ended up creating a new field to import the second entity reference.

Status: Fixed » Closed (fixed)

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