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

Command icon 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

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review

This needs work on docs (and tests) but a custom plugin with this code that extends entity_generate works for me.

longwave’s picture

Issue summary: View changes
longwave’s picture

It just struck me that values here is just an entire process pipeline, and get is the default, so perhaps we can do away with the loop entirely!

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This 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.

jeremy1606 made their first commit to this issue’s fork.

jerech’s picture

Status: Needs work » Needs review

Commit 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.

heddn’s picture

Status: Needs review » Needs work

Test only execution do not fail. Needs some more work.

jerech’s picture

Status: Needs work » Needs review
heddn’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs documentation

We should add some doxygen about how to use this new feature. Otherwise, this is pretty much set to go.

jerech’s picture

Status: Needs work » Needs review

  • heddn committed 85213a24 on 6.0.x authored by longwave
    feat: #3542626 Allow entity_generate to run process pipelines on values...
heddn’s picture

Status: Needs review » Fixed

Thanks for the contribution.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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