Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any fallback value process exist or same can be achieved by existing ones ?
By fallback value plugin here I mean if I map a field to source X and if that source is null/empty, use source Y and so on.
Comments
Comment #2
heddndefault_value plugin provides some of this functionality. that, in combination with the lookup plugin might be enough for what you need.
Comment #3
joshi.rohit100@heddn - I agree for default value plugin but not sure about lookup (i think its entity_lookup you are refering) as lookup plugin looks for existing data but here we are looking in source.
Comment #4
mikeryanI wonder if this would work?
Comment #5
joshi.rohit100I think that will. thanks @mikeryan. One should never misunderstand the power of 'callback' :)
Comment #6
heddnComment #7
joshi.rohit100Adding for reference callable process plugin is callback
Comment #8
ultimikeOoo - this is a nice little pipeline!
-mike
Comment #9
mErilainen CreditAttribution: mErilainen at Wunder commentedDoesn't seem to work for me, I get:
"Parameter 1 to reset() expected to be a reference, value given Callback.php:66"
My use case is when creating terms the "nameEn" value is sometimes null, so I would like to fallback to the Finnish value:
Edit: Actually this works! The warnings scared me.
Comment #10
firfin CreditAttribution: firfin commentedWhile #9 works, this one seems cleaner to me as it doesn't generate errors. Difference is in the last line callable: 'current' instead of reset.
'content_access_settings/view':
-
plugin: get
source:
- '@content_access_view_legacy_unblock'
- '@content_access_view_wpmem_block'
- '@default_content_access_view'
-
# Filter out empty sources
plugin: callback
callable: array_filter
-
# Use the first non-empty source
plugin: callback
callable: 'current'