Problem/Motivation

The documentation in the entity_generate plugin is misleading.

Proposed resolution

See patch below.

Comments

BenStallings created an issue. See original summary.

benstallings’s picture

Status: Active » Needs review
StatusFileSize
new2.19 KB
danflanagan8’s picture

Status: Needs review » Needs work

This is a really good idea if you ask me! Here are my humble thoughts on the proposed changes.

+++ b/src/Plugin/migrate/process/EntityGenerate.php
@@ -27,7 +31,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
+ * Example where 'tags' is a string of text, for example from an XML file:

More likely this example intends for tags to be an array of strings that correspond to tag names. I also don't think we need to mention XML, even though it's true that the source might be XML.

The new example is super cool, but it doesn't look quite right to me. I would think the following would work better:

process:
 field_media:
     plugin: sub_process
     source: field_image
     process:
       target_id:
         -
           plugin: migration_lookup
           migration: d7_file
           source: fid
           no_stub: true
         -
           plugin: entity_generate
           entity_type: media
           bundle_key: bundle
           bundle: image
           value_key: field_media_image
           values:
             name: alt # use the image's alt text as the media name, why not?
           default_value:
             uid: 1

I think that would get the alt from field_image correctly onto the media instead of having to use a default value. This uses the image's alt for the media name in order to demonstrate the values key. I think including an example of the default value is a great idea so I put the uid on there.

I haven't tested that though. I should do that! I tested and made some edits.