-
-
Save BERRAMOU/25d8ad750fd92a443a9cbba6061cda2e to your computer and use it in GitHub Desktop.
How to migrate multi-value link field in Drupal 8
This file contains 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 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