Skip to content

Instantly share code, notes, and snippets.

@BERRAMOU
Forked from rocketeerbkw/example.php
Created March 14, 2019 22:47
Show Gist options
  • Save BERRAMOU/25d8ad750fd92a443a9cbba6061cda2e to your computer and use it in GitHub Desktop.
Save BERRAMOU/25d8ad750fd92a443a9cbba6061cda2e to your computer and use it in GitHub Desktop.
How to migrate multi-value link field in Drupal 8
<?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);
}
}
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