2

I created my own Yaml file with fields inside to migrate nodes.

I run into this problem. If I use the feeds module, I can set (during mappings) that a given field (taxonomy term reference field) can be referenced by any other field from my site. The term name is therefore assigned based on the value in the reference field.

If I use Migrate CSV module, how do I set this in Yaml file? This is my Yaml:

uuid: bf1e53ae-6a95-48f2-8888-4b928e6e33ea

id: testovacimigrace2
label: My own migration !!!!!!!
migration_group: migration

source:
  plugin: 'csv'
  # Full path to the file.
  path: 'modules/custom/migrace/assets/csv/upload1.csv'
  delimiter: ','
  enclosure: '"'
  header_row_count: 1
  ids:
    - ID

process:
  title: title
  field_email: email  
  type:
    plugin: default_value
    default_value: submitlawyer 

destination:
  plugin: entity:node
  1. Every term in my taxonomy called "fishes" has its own field with a unique number.

  2. My CSV contains a column called fish that does not contain a term name but its unique number (ad.1)

  3. I need to assign the correct term by using this unique number.

1 Answer 1

2

Here is a simple migration for looking up a taxonomy term by name based on the text in a CSV.

taxonomy_field_name:
  plugin: entity_lookup
  source: name_of_source_column
  value_key: name
  bundle_key: vid
  bundle: name_of_taxonomy
  entity_type: taxonomy_term

For example, if you have a taxonomy called fishes, and your CSV has a column called fish, and your node has a field called field_fish which is an entityreference to a taxonomy term of the fishes vocabulary, and there is a taxonomy term "Carp" with entity ID 14

field_fish:
  plugin: entity_lookup
  source: fish
  value_key: name
  bundle_key: vid
  bundle: fishes
  entity_type: taxonomy_term

Given a row in the CSV with "Carp" set as the fish, this will assign entity id 14 to that field.

Does that help? I am not sure what you mean by "a given field can be referenced by any other field from my site".

7
  • Thank you for a quick reply, Steve. Every term in my taxonomy called "fishes" has its own field with a unique number. My CSV contains a column called fish that does not contain a term name but its unique number (ad.1) I need to assign the correct term by using this unique number.
    – Hefi
    Jan 31, 2020 at 17:31
  • @Hefi if I understand you correctly now, you would change value_key: name to value_key: field_unique_number - where field_unique_number is the machine name of the field you added to those taxonomy terms Jan 31, 2020 at 18:46
  • Yes, but "field_unique_number" value is only needed to assign a name of the given term. But when i use the term field "field_unique_number" as a value_key, the terms are not associated with the node.
    – Hefi
    Jan 31, 2020 at 19:04
  • Just to confirm, you have actually added field_unique_number to the taxonomy bundle fishes, all terms within that vocabulary have that field, and it is populated? So if you go to your term "Carp" in the /admin/structure/taxonomy area, you can see it definitely has a field_unique_number of, say, "22". And you have definitely have 22 in the fish source column of your csv, and you've double checked that source column is correctly named, and the field_fish is correctly named with respect to the node, etc? But when you run the migration it still fails to match? If so... I'm stuck Jan 31, 2020 at 19:17
  • @Hefi when you say "field unique number is only needed to assign a name", do you mean, you haven't actually created a field, and added it and populated it, because it's only needed during import and you don't want to clutter your database with that as a permanent field? If so, perhaps the static map plugin is the answer. It will allow you to set up a simple yaml mapping like 22: Carp which you can feed down the pipeline to lookup taxon term by name. Jan 31, 2020 at 19:38

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.