Empty
Last updated on
20 November 2022
Available configuration keys:
- negate: (optional) Whether the 'empty' condition should be negated. Defaults to FALSE. You can also negate the 'empty' plugin by using 'not:empty' as the plugin id.
- source: (optional) Property or array of properties on which to evaluate the condition. If not set, the condition will be evaluated on the source passed to the ::evaluate() method, typically the source of the process plugin that is using this condition.
Examples
1. Skip on empty with clear array handling
The core skip_on_empty process plugin can have trouble with arrays. (See #3254356: [meta] skip_on_empty problems with arrays). But unlike skip_on_empty, the skip_on_condition process plugin "handles multiples", which allows us to solve problems more exactly.
Skip the row when the source is an empty array.
process:
skip_on_empty_array:
plugin: skip_on_condition
condition: empty
source: my_source_array
method: row
message: 'The source array was empty'Or we can skip if any value in the source array is empty.
process:
skip_if_any_array_element_is_empty:
plugin: skip_on_condition
condition:
plugin: has_element
condition: empty
source: my_source_array
method: row
message: 'At least one element of the array was empty'2. Negate a boolean
That is, change TRUE to FALSE and FALSE to TRUE. This can be done with a static map, but my goodness is the following clearer.
process:
field_boolean:
plugin: evaluate_condition
condition: not:empty
source: my_source_boolean_with_the_wrong_sign
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion