Skip Empty Values During Concatenation in a Drupal 10 Migration
UPDATE. You can do the same as below without the need for a custom module function. (source)
1 2 3 4 5 6 7 8 9 |
field_address_full: - plugin: callback callable: array_filter source: - address_1 - city - state - plugin: concat delimiter: ', ' |
This quick example shows one method to ignore empty values in a Drupal 10 migration concatenate process.
Code
Migrate code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
process: temp_address_parts: - plugin: skip_on_empty method: process source: - address_1 - city - state - plugin: callback callable: mymodule_migrate_filter_empty field_address_full: plugin: concat delimiter: ', ' source: '@temp_address_parts' |
Module code:
1 2 3 4 5 6 7 8 |
/** * Filters out empty values from an array. */ function mymodule_migrate_filter_empty($values): array { return array_filter($values, function ($value) { return !empty($value); }); } |
Result
Example data:
1 2 3 4 |
address_1,city,state 1 Main St.,Portland,ME 2 Main St.,Portland ,Portland,ME |
Resulting field_address_full plain text value
1 2 3 |
1 Main St., Portland, ME 1 Main St., Portland Portland, ME |