Migrate multivalue fields into unlimited Custom Fields field

Last updated on
26 February 2025

An easy way to import content into a multi-value Custom Field field with unlimited values, is with data in JSON-format and using the sub_process Migrate plugin from Drupal core.

Install Migrate Plus to support JSON-format and get the url migrate source plugin.

For this example, create a Custom Field field called "Hyperlink" with machine name hyperlink in the Article content type, with two Custom Field items (AKA "sub-fields"):

  • "Link text" with machine name linktext
  • "URL" with machine name linkurl

The source file:

[
{
  "id": 299,
  "title": "Custom Field hyperlink import",
  "hyperlink":
    [
      {
        "linkurl_source": "https://drupal.org",
        "linktext_source": "Drupal"
      },
      {
      "linkurl_source": "https://www.example.com",
      "linktext_source": "Example Website"
      },
      {
        "linkurl_source": "https://gitlab.com/",
        "linktext_source": "GitLab"
      }
    ]
  }
]

Create a custom migration module called "migrations" with this structure:

migrations/
├── custom_field_hyperlink.json
├── migrations
│   ├── custom_field_hyperlink.yml
└── migrations.info.yml

... and with this in custom_field_hyperlink.yml:

id: custom_field_hyperlink
label: Custom field import
source:
  plugin: url
  data_fetcher_plugin: file
  data_parser_plugin: json
  urls: modules/custom/migrations/custom_field_hyperlink.json
  fields:
    -
      name: id
      selector: id
    -
      name: title
      selector: title
    -
      name: hyperlink
      selector: hyperlink
  ids:
    id:
      type: integer
process:
  nid: id
  title: title
  field_hyperlink:
    plugin: sub_process
    source: hyperlink
    process:
      linkurl: linkurl_source
      linktext: linktext_source
destination:
  plugin: entity:node
  default_bundle: article

Now, you should be able to import pairs of data into an unlimited Custom Field field.

Help improve this page

Page status: No known problems

You can: