- π¬π§United Kingdom very_random_man
In case anyone comes across this like I did, looking for a way to to use entity_generate with entity_reference_revisions, here's how you can do it just with some process magic. In the example below I have a phone field from a D7 field source (field_contact_phone) and I'm using that to generate a custom multi_field entity which has separate label and phone fields. The important part is the last bit which looks up the revision ID using an entity_value plugin.
field_phone: - plugin: sub_process source: field_contact_phone process: _linklabel: linklabel target_id: plugin: entity_generate source: phonenumber entity_type: multi_field bundle: labelled_phone value_key: field_phone_number bundle_key: bundle values: label: '@_linklabel' field_phone_number/0/value: phonenumber _revision_id_value: plugin: entity_value source: '@target_id' entity_type: multi_field field_name: revision_id target_revision_id: '@_revision_id_value/0/value'
- π¬π§United Kingdom natts London
Thanks for that @very_random_man. I was doing something more simple with a entity reference field for media, and didn't know that I needed to use target_id as the attribute of the field to assign the generated entity to it, but your code showed me that's what I was missing:
process: youtube_1/url: youtube1 youtube_2/url: youtube2 youtube_3/url: youtube3 vimeo_1/url: vimeo videos: - plugin: get source: - '@youtube_1' - '@youtube_2' - '@youtube_3' - '@vimeo_1' field_videos: plugin: sub_process source: '@videos' process: target_id: - plugin: skip_on_empty source: url method: process - plugin: entity_generate source: url entity_type: media bundle: remote_video bundle_key: bundle value_key: field_media_oembed_video values: field_media_oembed_video: url
- π©πͺGermany vistree
@very_random_man - you saved my day!! I were able to migrate paragraphs with your method without any problems ;-)
Thanx so much!!My paragraph (colorscheme) has 5 input fields:
- id (unique identifiere)
- hex
- type
- color (name)
- menu (to be used within the menu)
field_colorscheme: - plugin: skip_on_empty method: process source: colorscheme - plugin: sub_process process: _menu: menu _hex: hex _type: type _color: color target_id: plugin: entity_generate source: id entity_type: paragraph bundle: color_set value_key: field_remote_id bundle_key: type values: field_remote_id/0/value: id field_color_menu/0/value: '@_menu' field_color_value/0/color: '@_hex' field_title/0/value: '@_type' field_color_type/0/value: '@_color' _revision_id_value: plugin: entity_value source: '@target_id' entity_type: paragraph field_name: revision_id target_revision_id: '@_revision_id_value/0/value'
- π¬π§United Kingdom nicholasthompson
Another handy way of using entity_generate, granted not paragraphs here, but might help someone (or Future-Me)
_imageLookup: plugin: migration_lookup migration: migrate_file_managed source: field_image/0/fid field_media_image: plugin: entity_generate access_check: false entity_type: media source: '@_imageLookup' value_key: name ignore_case: true default_values: bundle: 'image' values: name: '@_imageLookup/filename' field_media_image: '@_imageLookup'
This creates an entity:image during a node migrate.
- π©πͺGermany vistree
Anybody an idea on how to use entity_generate to add NON existing files to media items?
I am in trouble with source and destination ... - π¬π§United Kingdom joekers UK
The entity_value plugin here was the key for me - thanks @very_random_man!
- πΊπ¦Ukraine bohdan vasyliuk
I have successfully generated paragraphs using entity_generate. However, when I executed migrate:rollback, the nodes were removed, while the paragraphs generated by the migration remained in the database.
Consequently, there is a risk of having numerous orphan paragraphs, which may be related to this issue: https://www.drupal.org/project/paragraphs/issues/3056819 π Remove orphan paragraphs when host entity is removed Closed: duplicate . Please correct me if I'm wrong. - π¬π§United Kingdom Baysaa
@Bohdan that's correct, things created using entity_generate won't have a migrate_map table created for them, so they won't get rolled back naturally.
You'll have to snapshot/create restore points for your DB while doing these things I found.