I am migrating CSV data into Nodes and Paragraphs in Drupal 8.
I have field in CSV file which has JSON data, I have written a process plugin to convert JSON data to multi-dimensional array.
I would like to know a way to pass the each sub array to my another custom process plugin. Is there any such process plugin available to pipe sub array from parental array in core migrate
or through migrate_plus
module.
I am looking for something similar so that it passes only sub array into the final custom process plugin.
pseudo_field_country_time_zones:
- # plugin which converts JSON data to multi dimensional array.
plugin: country_timezones_data_formatter
source: timezones
- # not sure if this is correct plugin to process array.
plugin: sub_process
-
plugin: country_timezones_paragraphs
You might ask why cant you process the data in the country_timezones_paragraphs
process plugin itself. That plugin is being used by other process, so dont want to change it. Other solution for me is to write another process plugin but it will be just code duplication with foreach loop added to country_timezones_paragraphs
.
I believe there is already a plugin available either from migrate or migrate_plus module for this scenario , but not able to identify what it is.
$input_data = '[{"zoneName":"Africa Ceuta","gmtOffset":3600,"gmtOffsetName":"UTC+01:00","abbreviation":"CET","tzName":"Central European Time"},{"zoneName":"Atlantic Canary","gmtOffset":0,"gmtOffsetName":"UTC\u00b100","abbreviation":"WET","tzName":"Western European Time"},{"zoneName":"Europe Madrid","gmtOffset":3600,"gmtOffsetName":"UTC+01:00","abbreviation":"CET","tzName":"Central European Time"}]';
Decoded JSON array.
$decoded_array = var_dump(json_decode($input_data, TRUE));
Array
(
[0] => Array
(
[zoneName] => Africa Ceuta
[gmtOffset] => 3600
[gmtOffsetName] => UTC+01:00
[abbreviation] => CET
[tzName] => Central European Time
)
[1] => Array
(
[zoneName] => Atlantic Canary
[gmtOffset] => 0
[gmtOffsetName] => UTC±00
[abbreviation] => WET
[tzName] => Western European Time
)
[2] => Array
(
[zoneName] => Europe Madrid
[gmtOffset] => 3600
[gmtOffsetName] => UTC+01:00
[abbreviation] => CET
[tzName] => Central European Time
)
)