4

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');
5

I was able to solve it :-)

This helped me: https://www.drupal.org/node/2594631#comment-11322879

It is important to map all addressfield subfields, otherwise it will not work.

  • 3
    If you can post an example here rather then only a link, it would be better. – Jimmy Ko Jul 30 '16 at 14:54
  • To have duplicate content? I do not think that is a good idea. – Sebastian Nov 29 '16 at 17:00
  • 2
    It is not a shame if you provide the link where you copy from. Because the 3rd party source can be not found in future. It is encouraged in Drupal Answer and also Stackoverflow. – Jimmy Ko Nov 29 '16 at 17:21
  • 1
    Just to elaborate on Sebastian's comment. If you try and just migrate one field (say address_line1) it will not work. You need to migrate all the fields (or at least address_line1, country_code, langcode, locality, postal_code and administrative_area). I got stuck on this for quite a while. – chap May 4 '18 at 1:34
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

Can you please give any example any example we can have for Source migration as SQL Currently I am facing a issue in migration addressfield from Drupal 7 to Drupal 8 Address field

There are no migration path currently for Address field any suggestion will be helpful

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, privacy policy and cookie policy

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