Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Instead of providing a fixed default value it would be nice to get it from a source field. For example if you want to set a destination field_nickname which should get the value from source_nickname, but if that is empty it should get the value from source_name.
Comment | File | Size | Author |
---|---|---|---|
#2 | migrate_plus-plugins-get_default_value-2880413-2.patch | 1.95 KB | osopolar |
Comments
Comment #2
osopolarComment #3
heddnI feel like this could be done with skip_on_value, which is already in migrate_plus.
Comment #4
mikeryanYes, this seems unnecessary. It's not really getting a default value, it's saying use the first non-empty value among these source properties, which can be done with skip_on_value, or something like
Alright, that was more elaborate than I expected, skip_on_value makes more sense...
Comment #5
osopolarThanks for your help. I have searched for process plugins. The only one which seemed helpful was the array merge plugin, but it seemed to complicate to build the migration that way. I was not aware of skip_on_value, and now I am, but not sure on how to use it (in above example). Would be nice if you may explain the use of that plugin here and/or in the plugin documentation.
My actual use case (to migrate content access settings) looks a bit more complicated and with #4 it might be even harder to understand what's going on there. That's why I wrote the get_default_value process plugin, and thought there could be some common use for it.
Comment #6
osopolarI rewrote my migration with the information in #4 and it does not look that bad ;) ... but it don't work, ans it gives me the error:
That's because reset() expects a reference to actually reset the array pointer and call_user_func used in Callback.php only passes parameters by value. Hopefully the the pointer is already at the first element so the current callback could be used:
Anyway, I would like to see how to implement #4 using the skip_on_value plugin. Maybe it would be helpful for others too, as there is not much documentation about it.
Comment #7
heddnBased on the gist here from @osopolar, it doesn't seem like this is necessary: https://gist.github.com/osopolar/4604995624932507654f42f655ae979e
Comment #8
osopolarContent of above mentioned gist:
I like that solution, which is based on input from #4 (thank you mikeryan), as it is very clean.
Anyway, the get_default_value Plugin, which just combines the get and the default_value plugins, is still useful to me. I'll add it to my custom migrate module. Here the source code, if anybody else needs it:
Comment #9
osopolarActually it's a duplicate of.