I cannot seem to get the entity_lookup plugin to work with the default_value plugin.
I am migrating data from a CSV file into nodes.
The field field_faculty_role is a term reference. If that field is left blank in the source (field name is "role"), I would like the migration to use a default value.
I first tried running the migration without worrying about the default value.
field_faculty_role:
plugin: entity_lookup
source: role
ignore_case: true
value_key: name
entity_type: taxonomy_term
bundle_key: vid
bundle: person_type
This works fine. Rows in the source with roles field blank are imported but field_faculty_role is left emtpy.
Then I tried adding the default value plugin to the process pipeline like so:
field_faculty_role:
plugin: get
source: role
plugin: default_value
source: Full-Time (tried this with and without surrounding quotes)
plugin: entity_lookup
ignore_case: true
value_key: name
entity_type: taxonomy_term
bundle_key: vid
bundle: person_type
I got an error message "Error: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for [error column 'tid' at row 1]"
I interpret this to mean that entity_lookup was not receiving either data from role, nor the default value.
I tried removing the default_value plugin so I was left with:
field_faculty_role:
plugin: get
source: role
plugin: entity_lookup
ignore_case: true
value_key: name
entity_type: taxonomy_term
bundle_key: vid
bundle: person_type
Got the same error. Confirmed with a print_r($value) in EntityLookup that the plugin was not receiving the values in the pipeline.
Then I tried adding the code to "source" inside the entity_lookup config.
field_faculty_role:
plugin: entity_lookup
ignore_case: true
value_key: name
entity_type: taxonomy_term
bundle_key: vid
bundle: person_type
source:
plugin: get
source: role
Works fine.
Then I added default_value back.
field_faculty_role:
plugin: entity_lookup
ignore_case: true
value_key: name
entity_type: taxonomy_term
bundle_key: vid
bundle: person_type
source:
plugin: get
source: role
plugin: default_value
default_value: Full-Time
The migration works but rows with no role do not get the default value.
Has anyone else run into this issue? I'm trying to figure out how to troubleshoot it further.
Comments
Comment #2
esomething CreditAttribution: esomething commentedComment #3
esomething CreditAttribution: esomething commentedI figured this one out.
I was missing a dash (-) between plugins to tell Drupal it was an array of plugins.
Code that works is:
Comment #4
esomething CreditAttribution: esomething commented