My goal is to import json file into Drupal 8 using Migrate modules (migrate_plus, migrate_tools).
I use Paragraph module with fields like Name (entity reference) and composition (Number-float). And in node, I have title and other fields with Paragraph reference field.
I do import, sometimes the node will be generated with blank paragraph name, If I reset migrate and try to import again, db logs gives following error
Error: Unsupported operand types in Drupal\migrate\Plugin\migrate\process\SubProcess->transform() (line 204 of C:\xampp\htdocs\drupal-migration\core\modules\migrate\src\Plugin\migrate\process\SubProcess.php) #0 C:\xampp\htdocs\drupal-migration\core\modules\migrate\src\MigrateExecutable.php(394): Drupal\migrate\Plugin\migrate\process\SubProcess->transform(Array, Object(Drupal\migrate_tools\MigrateBatchExecutable), Object(Drupal\migrate\Row), 'field_ingredien...')
but I can't figure out why importing is not working. I spent lots of time to debugging.
And also node is not created if ic_ref
value is empty,
{
"lcia_id": 3,
"name": "Freeze-dried blueberries",
"net_weight": 1,
"country": "United Kingdom",
"ic_ref": ""
}
Migration configuration for Ingredients(config/install/migrate_plus.migration.icm_config_group_json_source_node)
item_selector: /data/ingredients/
fields:
-
name: src_lcia_id
label: 'LCIA ID'
selector: lcia_id
-
name: src_name
label: 'Ingredient Name'
selector: name
-
name: src_ic_ref
label: 'IC paragraph ID'
selector: ic_ref
ids:
src_lcia_id:
type: integer
process:
title:
plugin: concat
source:
- src_name
- constants/TITLE_SUFFIX
pseudo_mbe_ic_paragraph:
plugin: migration_lookup
migration: icm_config_group_json_source_paragraph
source: src_ic_ref
field_ingredient_composition:
plugin: sub_process
source:
- '@pseudo_mbe_ic_paragraph'
process:
target_id: '0'
target_revision_id: '1'
destination:
plugin: 'entity:node'
default_bundle: ingredient
migration_dependencies:
required:
- icm_config_group_json_source_paragraph
optional: { }
Migration configuration for Ingredients(config/install/migrate_plus.migration.icm_config_group_json_source_paragraph)
source:
item_selector: /data/composition
fields:
-
name: src_lcia_id
label: 'LCIA ID'
selector: lcia_id
-
name: src_name
label: 'Ingredient Name'
selector: name
-
name: src_composition
label: 'Ingredient Composition'
selector: composition
ids:
src_lcia_id:
type: string
process:
field_ingredient_name: src_name
field_ingredient_composition: src_composition
destination:
plugin: 'entity_reference_revisions:paragraph'
default_bundle: ingredient_composition
migration_dependencies: null
JSON data
"data": {
"ingredients": [
{
"lcia_id": 1,
"name": "Plain Oats(conventional)",
"net_weight": 1,
"country": "United Kingdom, Republic of Ireland",
"ic_ref": 1
},
{
"lcia_id": 2,
"name": "Flavoured Sugar",
"net_weight": 1,
"country": "United Kingdom",
"ic_ref": 2
},
{
"lcia_id": 3,
"name": "Freeze-dried blueberries",
"net_weight": 1,
"country": "United Kingdom",
"ic_ref": ""
}
],
"composition": [
{
"lcia_id": 1,
"name": "Sugar",
"composition": 0.9398839137645107
},
{
"lcia_id": 2,
"name": "Yeast",
"composition": 0.04975124378109454
}
]
}
}```