OK, I tried working at this one and couldn't figure out the solution, so I'm writing up a request.
I'm trying to import Paragraphs using Migrate Source CSV. I've managed to get single paragraphs to import using Migrate.
However when I attempt to import multiple paragraphs using the explode plugin - everything seems to break.
Here's my migrate YML:
uuid: 88b8d4b8-0887-4dbf-884e-1d2483c3f2c0
id: import_content_test_1
label: Import Content Test 1
source:
plugin: csv
path: 'private://import_csv/content_test_1.csv'
header_row_count: 1
keys:
- id
column_names:
-
id: id
-
title: title
-
body: body
-
paragraph_test_1: paragraph_test_1
process:
title: title
body: body
'field_paragraph_test_1/target_id':
-
plugin: explode
source: paragraph_test_1
delimiter: ,
-
plugin: migration
migration: import_paragraph_test_1
no_stub: true
-
plugin: extract
index:
- 0
'field_paragraph_test_1/target_revision_id':
-
plugin: explode
source: paragraph_test_1
delimiter: ,
-
plugin: migration
migration: import_paragraph_test_1
no_stub: true
-
plugin: extract
index:
- 1
type:
plugin: default_value
default_value: content_test_1
destination:
plugin: entity:node
My CSV file has a row, with multiple values inside of it, e.g, "11,12", as follows:
id,title,body,paragraph_test_1
1,Title 1,Body 1,"11,12"
2,Title 2,Body 2,"21,22"
When I run the import, it fails, and generates the error:
Value is not a valid entity. [error]
(***/modules/entity_reference_revisions/src/Plugin/DataType/EntityReferenceRevisions.php:114)
If I dig into what EntityReferenceRevisions.php is expecting around line 114:
public function setValue($value, $notify = TRUE) {
unset($this->target);
unset($this->id);
unset($this->revision_id);
// Both the entity ID and the entity object may be passed as value. The
// reference may also be unset by passing NULL as value.
if (!isset($value)) {
$this->target = NULL;
}
elseif (is_object($value) && $value instanceof EntityInterface) {
$this->target = $value->getTypedData();
}
elseif (!is_scalar($value['target_id']) || !is_scalar($value['target_revision_id']) || $this->getTargetDefinition()->getEntityTypeId() === NULL) {
throw new \InvalidArgumentException('Value is not a valid entity.');
}
EntityReferenceRevisions::setValue taking in the following as $value:
Array
(
[target_id] => Array
(
[0] => 54
[1] => 56
)
[target_revision_id] => Array
(
[0] => 55
[1] => 57
)
)
This seems wrong to me.. presumably this should be an Array of two numbered objects, each containing an array with keys target_id, target_revision_id. I think *should* look closer to this:
Array
(
[0] => Array
(
[target_id] => 54
[target_revision_id] => 56
)
[1] => Array
(
[target_id] => 55
[target_revision_id] => 57
)
)
I'm guessing my YML file isn't quite what it should be. I've tried several iterations, usually attempting to put the explode before the breakdown into target_id/target_revision_id, something along the lines of the following (non working) YML code:
uuid: 88b8d4b8-0887-4dbf-884e-1d2483c3f2c0
id: import_content_test_1
label: Import Content Test 1
source:
plugin: csv
path: 'private://import_csv/content_test_1.csv'
header_row_count: 1
keys:
- id
column_names:
-
id: id
-
title: title
-
body: body
-
paragraph_test_1: paragraph_test_1
process:
title: title
body: body
field_paragraph_test_1:
plugin: explode
source: paragraph_test_1
delimiter: ,
process:
target_id:
-
plugin: migration
migration: import_paragraph_test_1
no_stub: true
-
plugin: extract
index:
- 0
target_revision_id:
-<ol>
<li></li>
</ol>
plugin: migration
migration: import_paragraph_test_1
no_stub: true
-
plugin: extract
index:
- 1
type:
plugin: default_value
default_value: content_test_1
destination:
plugin: entity:node
I can't quite figure this out (the sub-process isn't sure of its source?)
Any pointers would be helpful. Thanks in advance!