migrate_child_entity_generate
Security covered
This process plugin generates entities that only exist in context of their parent, eg. paragraphs.
The more commonly used entity_generate plugin by the Migrate Plus module does not support generating an entity by passing an array of values, and getting the entity fields from that array. This is mostly useful for generating entities that don't need to be checked for previous existence because they only exist in context of their parent, eg. paragraphs.
Example usage
destination:
plugin: 'entity:node'
source:
# assuming we're using a source plugin that lets us define fields like this
fields:
-
faq_items:
-
question: Some question
answer: Some answer
-
question: Another question
answer: Another answer
process:
field_faqs:
plugin: child_entity_generate
source: faq_items
entity_type: field_collection
bundle: faq
values:
field_faq_question: question
field_faq_answer/value: answer
default_values:
field_faq_answer/format: basic_html
If you want to store the whole value in a destination property instead of providing a mapping,
you can define the destination property name in the 'destination' key:
destination:
plugin: 'entity:node'
source:
# assuming we're using a source plugin that lets us define fields like this
fields:
-
questions:
- Some question
- Another question
process:
field_faqs:
plugin: child_entity_generate
source: questions
entity_type: field_collection
bundle: question
destination: field_question
If processing needs to happen on the values, you can pass them through the sub_process plugin first:
destination:
plugin: 'entity:node'
source:
# assuming we're using a source plugin that lets us define fields like this
fields:
-
faq_items:
-
id: 100
isHighlighted: true
-
id: 101
isHighlighted: false
process:
field_faqs:
-
plugin: sub_process
source: faq_items
process:
entity:
plugin: migration_lookup
migration: faqs
source: id
isHighlighted: isHighlighted
-
plugin: child_entity_generate
entity_type: field_collection
bundle: faq
values:
field_faq_entity: entity
field_faq_is_highlighted: isHighlighted