Last active
June 23, 2023 18:42
-
-
Save rocketeerbkw/239219a6493c2adee34fb7ceb5af2072 to your computer and use it in GitHub Desktop.
How to migrate multi-value link field in Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Example extends SourcePluginBase { | |
public function prepareRow(Row $row) { | |
parent::prepareRow($row); | |
// I do some data manipulation to end up with an array that looks like this, | |
// which I want to import into multi-value link field. | |
$links = [ | |
[ | |
'title' => 'Link 1', | |
'uri' => 'URI 1', | |
], | |
[ | |
'title' => 'Link 2', | |
'uri' => 'URI 2', | |
], | |
[ | |
'title' => 'Link 3', | |
'uri' => 'URI 3', | |
], | |
]; | |
$row->setSourceProperty('links', $links); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id: example | |
label: 'Example' | |
source: | |
plugin: example | |
keys: | |
- iid | |
process: | |
type: | |
plugin: default_value | |
default_value: example | |
title: title | |
# This is a multi-value drupal core link field. | |
# I want to migrate title and uri for each link. | |
# See example.php source plugin in this gist. | |
# This does not work. | |
field_links: links | |
# This also does not work. | |
'field_links/title': 'links/title' | |
'field_links/uri': 'links/uri' | |
# This worked! | |
field_links: | |
plugin: iterator | |
source: links | |
process: | |
title: title | |
uri: uri | |
destination: | |
plugin: 'entity:node' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those who need to import from a CSV file, here's an example of how it worked for me:
I created a preprocess so that the links were in this format:
CSV file:
And in migrate I did it this way: