Problem/Motivation
I am using Entity Generate to generate taxonomy terms on the fly, which seems like a common use case. My terms also have an image attached, which I also need to import.
The usual way of doing this is something like
process:
_location_image:
plugin: image_import
source: imageUrl
destination: constants/image_destination
alt: alternateText
field_location:
plugin: entity_generate
entity_type: taxonomy_term
bundle_key: vid
bundle: location
value_key: name
values:
field_image: '@_location_image'
However this imports the image for every row, even if the term already exists.
Steps to reproduce
Proposed resolution
I propose extending values so if the value is an array it is treated as a process plugin; this allows additional processing on other fields, but that is only run when the entity is created. For example:
process:
field_location:
plugin: entity_generate
entity_type: taxonomy_term
bundle_key: vid
bundle: location
value_key: name
values:
description/value:
plugin: snippet
module: custom_migrate
path: clean_html
source: locationDescription
description/format:
plugin: default_value
default_value: basic_html
path/alias:
plugin: str_replace
regex: true
source: locationUrl
search: '/^https?:\/\/[^\/]+/'
replace: ''
path/pathauto:
plugin: default_value
default_value: false
field_image:
plugin: image_import
source: imageUrl
destination: constants/image_destination
alt: alternateText
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork migrate_plus-3542626
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
longwaveThis needs work on docs (and tests) but a custom plugin with this code that extends
entity_generateworks for me.Comment #4
longwaveComment #5
longwaveIt just struck me that
valueshere is just an entire process pipeline, andgetis the default, so perhaps we can do away with the loop entirely!Comment #6
heddnThis is some of the oldest code in migrate_plus. Can we add tests to make sure this works how we expect and regressions don't break this? Also, we should add docs for how to make this super cool feature work.
Comment #8
jerech commentedCommit fba55534 demonstrates that the test will fail correctly if entity_type is missing.
Commit f20e3b11 demonstrates that the plugin depends on entity_type to function correctly.
Comment #9
heddnTest only execution do not fail. Needs some more work.
Comment #10
jerech commentedComment #11
heddnWe should add some doxygen about how to use this new feature. Otherwise, this is pretty much set to go.
Comment #12
jerech commentedComment #14
heddnThanks for the contribution.