0

There are a couple of questions that are closely related to this on this forum that I have reviewed several times. None of them seem to address the issue specifically.

I have a target field (with subfields) that is set to unlimited.

The Source that I'm "migrating" from is JSON. The Target, in this case, is an address field on a node.

To simplify and debug the migration. I created a constant as a source for the values that I want to assign to field_locations/country_code.

The code in the migration configuration YAML is

source:
  constants:
    title_suffix: ' (Imported from remote file)'
    country: 'GB'
    countries:
      -
        country: US
      -
        country: CA
....

process:
  field_locations:
      plugin: sub_process
      source: 
        - constants/countries
      process:
        country_code: country

If I replace the implementation of the sub_process plugin and use get, I update the target field (subfield actually) with:

field_locations/country_code: constants/country

The destination row is updated perfectly - though of course I can only et

For reference: This is what the entity should look like with repeating values set. How do I get that to work with this migration? I'm guessing there is something pretty simple I'm missing

enter image description here

1 Answer 1

1

OK - I spent far more time than I care admit debugging this one. (doesn't help that PHPStorm is very unfriendly when it comes to stepping through a migration (e.g. I have not found a way to do it). Hope this saves someone from the frustration I had.

Problem one: Source was not formatted correctly. It MUST follow the following structure:

$source = [
  'countries' => [
    0 => [
      'country' => 'US',
    ],
    1 => [
      'country' => 'CA',
    ],
  ],
];

The YAML for that is:

  constants:
    countries:
      - country: 'US'
      - country: 'CA'

Problem two: The implementation of sub_process was a little off. And a little off is like being on the wrong planet. It should like this

  field_locations:
    plugin: sub_process
    source: constants/countries
    process:
      country_code: country 

One thing that is not obvious (and would never be if you were actually "migrating" from D7 to D8 for example, is the source.

Here, I am not actually migrating. It is an import from JSON. And, as it turns out, importing JSON can be a little unpredictable. The final "gotcha" was that the key "country" had to relate to the source (which it usually does). I had tried to slap in a different constant. (bad idea - though it could be done if that is really what is wanted.

Your Answer

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

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