So i have a migration set which creates new nodes during import from a json. Works as designed, but during import there are object which might have already been created, in this case only a certain field should be updated, and only under a certain condition.

Here is my migration.yml:

id: my_contacts
label: 'Contact migration'
  plugin: my_source
  track_changes: true
    plugin: default_value
    default_value: contact
  title/value: EN_Title
  field_email/value: EN_Email
  field_phone/value: EN_Phone
    plugin: default_value
    default_value: 1
    plugin: default_value
    default_value: 'published'
    plugin: default_value
    default_value: 1
  created: created
  plugin: entity:node
  default_bundle: contact
    - field_phone

So when i import, the field_phone will be overwritten if the id already exists, which is excellent, but i only want to do that under certain conditions. Idealy it would be a custom process plugin where i can compare some values.

pseudo-code (aka this is in pseudo-code what i would like to achieve):

  plugin: entity:node
  default_bundle: contact
    - field_phone:
        process: my_custom_process

And then in the process file:

 * @MigrateProcessPlugin(
 *   id = "my_custom_process"
 * )
class MyCustomProcess extends ProcessPluginBase
    public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
        if (condition) {
            return $value;
        } else {
            return null; //skip overwriting of this field???

If there is any other way to overwrite a field during migration if a condition is met that would be super?

Thanks, Will

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.