4

I would like to import some taxonomy terms with a taxonomy term in it. field_regio2 is a entityreference field to an existing taxonomy term Regio. But for some reason it is not working. Everything is working except the field_regio2.

$ drush mmsg import_gemeentes gives:

the entity_lookup plugin requires a value_key, none located

?

uuid: 7eef6b86-80db-40ab-8359-91d20675e0f2
langcode: en
status: true
dependencies: {  }
id: import_gemeentes
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags: null
migration_group: migrated_terms
label: 'Migrate gemeentes from the source CSV to taxonomy terms'
source:
  plugin: csv
  path: 'public://gemeentes.csv'
  header_row_count: 1
  keys:
    - id
  column_names:
    -
      id: id
    -
      vid: vid
    -
      name: name
    -
      field_stratenplan_luchtfoto_refe: field_stratenplan_luchtfoto_refe
    -
      rid: rid
    -
      rid22: rid2
process:
  vid:
    plugin: default_value
    default_value: gemeente
  name: name
  field_stratenplan_luchtfoto_refe: field_stratenplan_luchtfoto_refe
  field_regio: rid
  field_regio2:
    plugin: entity_generate
    source: rid22
destination:
  plugin: 'entity:taxonomy_term'
migration_dependencies: null
1
  • I have resolved the problem myself. For vid it is better to use the default_value plugin . I have updated the code, if someone needs it. First, I added an extra column in the CSV file vid = gemeente, but that is not working. – user3086053 Oct 19 '17 at 7:25
1

The syntax for entity_generate is:

field_regio2:
    plugin: entity_generate
    source: rid22
    entity_type: taxonomy_term
    # This is where migration breaks. It need to know which key to look for.
    value_key: name
    bundle_key: vid
    bundle: YOUR_VOCABULARY_MACHINE_NAME
0

It's important to realize that it's the value_key that will be matched to whatever is coming from the source. So if we say value_key: name then the source should contain strings (not IDs!) that will be matched to or create taxonomy term names.

Here's a working section of code from the process section of a node migration YAML-file. It gets names of category terms via source, matching them to names in vocabulary called "categories". If a a term with the given name does not exist in the vocabulary, it will be created.

# Name of the entityreference field, and we specify its property target_id:
field_category/target_id:
    plugin: entity_generate
    # "category" contains the textual name of the category, coming e.g. from CSV:
    source: category
    # Do not change this:
    entity_type: taxonomy_term
    # Do not change this:
    value_key: name
    # Do not change this:
    bundle_key: vid
    # Machine name of your vocabulary:
    bundle: categories

Here's the best page ever I've found on the subject: https://understanddrupal.com/articles/understanding-entitylookup-and-entitygenerate-process-plugins-migrate-tools

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.