I'm doing a D7 to D8 custom migration. In Drupal 7, I have a multi-value formatted text field that I am trying to map to a Drupal 8 multi-value Paragraph entity reference field.
I've separated this into two migrations. One for the paragraphs, and one for the nodes themselves. I've got the multi-value field to paragraph migration working (although I think there might be an issue with the way that I have done the IDs). I have the node migration working as well, with the exception that none of the references to the already migrated paragraph entities are being migrated.
I realize that right now, this seems unnecessary, but it's part of a feature upgrade.
Below is the code from my migration classes/plugins.
This is from migrate_plus.migration.presentation_node.yml
.
Field_slide is the paragraph reference field.
'field_slide/target_id':
plugin: migration
migration: presentation_slide
source: entity_id
This is the getIds function from PresentationSlide.php
. This is the plugin for the paragraph migration.
public function getIds() {
return [
'entity_id' => [
'type' => 'integer',
'alias' => 'lt',
],
];
}
This is also from PresentationSlide.php
. Here I am combining the entity_id and delta to form a unique id. I realize that this is a terrible way to do this, but I couldn't figure out anything better. Any tips on this are welcome.
public function prepareRow(Row $row) {
$nid = $row->getSourceProperty('entity_id');
$delta = $row->getSourceProperty('delta');
$slide_id = (string) $nid . (string) $delta;
$slide_id = (int) $slide_id;
$row->setSourceProperty('entity_id', $slide_id);
return parent::prepareRow($row);
}
And this is from PresentationNode.php
. Here I am fetching all of the referenced fields, and passing that as an array to the migration class.
public function prepareRow(Row $row) {
$nid = $row->getSourceProperty('nid');
$query = $this->select('field_data_field_learning_text', 'lt')
->condition('entity_id', $nid);
$query->addExpression('CONCAT(entity_id, delta)', 'target_id');
$slides = $query->execute()->fetchCol();
if (!empty($slides)) {
$row->setSourceProperty('entity_id', $slides);
}
return parent::prepareRow($row);
}
The main issue here is that I can't figure out how to properly use a multiple column key. It seems to me that all of my issues are due to my doing this improperly.
Thanks in advance. I realize this is a lot.
[Edit]
Thanks Berdir for the help. I've taken a stab at implementing your processing plugin. However, I'm having an issue where the migration seems to be skipping right over and ignoring the process plugin.
field_slide:
plugin: paragraph_process_base
source: field_body_value
Feel like there is something super simple that I'm missing here.
[Edit 2] And I had a typo... Thanks a ton!