2

I’ve got a D7 to D8 migration where I’m trying to migrate a field with a null value in D7 to a default value in D8. Process pipeline is similar to this:

  field_privacy:
    -
      plugin: get
      source: field_office_privacy
    -
      plugin: default_value
      default_value: 'open’

It seems if the field value is null, the default_value plugin never runs.

When D7 has a non-null value, then the field migrates perfectly via the get plugin. The D8 API documentation gives this pipeline as an example of exactly what I'm trying to do, yet I cannot get it to work. When I should get a value for all 164 items selected by the migration source, I instead only get 132, which precisely matches the number of fields in D7 that have non-null values.

How can I set a default value when get doesn't find a value?

1

The catch here is that you should not use the get process plugin explicitly. The behaviour you want is already implicitly used the default_value plugin. This is because get is the default process plugin and can be shorthanded. In your case this should work:

 field_privacy:
   plugin: default_value
   source: field_office_privacy
   default_value: 'open’

Also see documentation for get and default_value

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.