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

joshi.rohit100 created an issue. See original summary.

heddn’s picture

default_value plugin provides some of this functionality. that, in combination with the lookup plugin might be enough for what you need.

joshi.rohit100’s picture

@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.

mikeryan’s picture

I wonder if this would work?

process:
  field_foo:
    -
      plugin: get
      source:
        - X
        - Y
    -
      plugin: callable
      callable: array_filter
    -
      plugin: callable
      callable: reset
joshi.rohit100’s picture

I think that will. thanks @mikeryan. One should never misunderstand the power of 'callback' :)

heddn’s picture

Status: Active » Closed (works as designed)
joshi.rohit100’s picture

Adding for reference callable process plugin is callback

ultimike’s picture

Ooo - this is a nice little pipeline!

-mike

mErilainen’s picture

Doesn'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:

  name:
    -
      plugin: get
      langcode: constants/langcode
      source:
        - nameEn
        - nameFi
    -
      plugin: callback
      callable: array_filter
    -
      plugin: callback
      callable: reset

Edit: Actually this works! The warnings scared me.

firfin’s picture

While #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'