8

I am currently searching for a example to migrate data into an address field in Drupal 8 without any luck for now.

Has someone a hint for me on how to map the fields?

I tried the following:

my.migrate.yml file:

'field_date_address/address_line1': date_tmp_address_address_line1
'field_date_address/locality': date_tmp_address_locality
'field_date_address/postal_code': date_tmp_address_postal_code

Callback:

$row->setSourceProperty('date_tmp_address_address_line1', 'Teststreet 18');
$row->setSourceProperty('date_tmp_address_locality', 'Test locallity');
$row->setSourceProperty('date_tmp_address_postal_code', '12345');
1

2 Answers 2

0

I do migrate from json to drupal 8, hope this will help.

In the .yml I call the field on a single value :

id: my_id_migrate
label: My Label
migration_group: MyGroup
migration_dependencies: {}

source:
  plugin: json_source
  path: URL_TO_JSON_FILE
  headers:
    Accept: 'application/json'
  identifier: id
  identifierDepth: 0
  fields:
    - id
    - title
    - address

destination:
  plugin: entity:node

process:
  type:
    plugin: default_value
    default_value: my_node_type

  title: title

  field_geolocation : geolocation
  field_address : address

And 'address' is an array of all subfields :

.json source :

[
   {
      "id":1,
      "title":"Title 1",
      "address":{
         "address_line1":"adress 1",
         "address_line2":"",
         "postal_code":"11111",
         "locality":"City of lights",
         "country_code":"DE"
      },
   },
   {
      "id":2,
      "title":"Title 2",
      "address":{
         "address_line1":"adress 1 of number2",
         "address_line2":"",
         "postal_code":"11111",
         "locality":"City of lights",
         "country-code":"DE"
      },
   },
   {
      "id":3,
      "title":"Title 3",
      "address":{
         "address_line1":"adress 1 of number3",
         "address_line2":"",
         "postal_code":"11111",
         "locality":"City of lights",
         "country_code":"DE"
      },
   }
]

Works with all subfields, and works fine for all fields in drupal 8 that have subfields (like geolocation fields for example)

0

Here is a working example with a user profile migration (not Drupal user account).

Adress is an array of subfields. You can check in database all the possible subfields because i don’t use all of them (ex : field_profile_address_family_name)

.yml file :

field_profile_address/country_code:
     plugin: default_value
     default_value: FR
   field_profile_address/langcode:
     plugin: default_value
     default_value: fr
   field_profile_address/address_line1: adresse1
   field_profile_address/address_line1: adresse2
   field_profile_address/locality: ville

   field_profile_address/postal_code: code_postal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.