- Issue created by @elvin - albania drupal developer
- π¦π±Albania elvin - albania drupal developer
I did end up solving my issue by updating the mapping to return an array as well and used extraxt to get either value
pseudo_test_img_source: - plugin: default_value source: field_wms_bg_image default_value: para_cta pseudo_bundle: - plugin: static_map source: '@pseudo_test_img_source' map: 'para_cta': - para_cta default_value: 'para_cta_img' - plugin: extract index: - 0 type: '@pseudo_bundle'
Still wonder if static_map should get altered -_-
- Status changed to Closed: works as designed
over 1 year ago 12:22pm 22 June 2023 - πΊπΈUnited States mikelutz Michigan, USA
Static map doesn't change it's return value based on whether it finds a value or not, your result is expected behavior due to the way the two plugins handle multiple valued fields. Default value handles multiple valued arrays all at once, static map acts once per each array item. (This is intentional and a feature of process plugins)
In your case, practically this means in the first case, default value sees an empty array, determines that it needs to set a default value and sets pseudo_image_test_source to a string. In the second case, it sees the whole array, determines that it doesn't need to set a default, and sets pseudo_image_test_source to the same multi-valued array it was called with.
Then you get to static map. In the first case, static map sees a string, and replaces the value as expected.
In the second cases, the system sees that the input is a multi-valued array (with one item, but still a multi-valued array from the processors standpoint) and that static_map has asked to receive each array item one by one in the case of a multi-valued array.So instead of static_map seeing
array:1 [ 0 => array:5 [ "fid" => "4343" "alt" => "" "title" => "" "width" => "3264" "height" => "2448" ] ]
The system loops through the outer array and passes the first element to static_map
array:5 [ "fid" => "4343" "alt" => "" "title" => "" "width" => "3264" "height" => "2448" ]
The map sees this isn't in its list so it returns the default, which the system properly inserts in the same spot in the original array.
In your case, to make what you have work, I would run this:
pseudo_test_img_source: - plugin: default_value source: field_wms_bg_image<strong>/0/fid</strong> default_value: para_cta pseudo_bundle: - plugin: static_map source: '@pseudo_test_img_source' map: 'para_cta': para_cta default_value: 'para_cta_img' type: '@pseudo_bundle'
or my personal preference on this situation (note: this isn't better or worse than the corrected version of your way, I think I just like having an excuse to use null_coalesce)
source: constants: para_cta:para_cta para_cta_img: para_cta_img process: _has_img: - plugin: skip_on_empty source: field_wms_bg_image/0/fid method: process - plugin: get source: constants/para_cta_img type: plugin: null_coalesce source: - "@_has_img" - constants/para_cta
Also the Migrate Conditions β module has some nice process plugins to deal with this type of conditional processing as well.
Also to note, the #migration slack channel is a good place to try to get help with this type of debugging in real time if you haven't been there. They can talk you through the issue and help determine if there's something to fix in your migration or a real bug that needs to have an issue filed.
- π¦π±Albania elvin - albania drupal developer
Thanks a lot @mikeluts for the time and thorough reply! I did not think of using null_coalesce
I did lots of trial and error till i reached my end solution and stuck with that as it did get the job done fine at the moment.