And Condition
This condition allows logical combinations of other conditions.
Available configuration keys:
-
condition: An array of arrays. Each element must have a 'plugin' key that is the id of the condition. Any additional properties will be used as configuration when creating an instance of the condition.
-
iterate: (optional) The default value is FALSE. If 'iterate' is FALSE, Each condition is evaluated on the source value. If 'iterate' is TRUE, then each condition is evaluated on the element in the source that has the corresponding index/key. Thus, when 'iterate' is TRUE, the source must be an array.
-
negate: (optional) Whether the 'and' condition should be negated. Defaults to FALSE. You can also negate the 'and' plugin by using 'not:and' 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. Set a boolean value is_a_teenager based on source_age
process:
is_a_teenager:
plugin: evaluate_condition
source: source_age
condition:
plugin: and
conditions:
-
plugin: not:less_than
value: 13
-
plugin: less_than
value: 202. Set a boolean if a source value is 5.
This is overly complicated. It should really be done with a single equals condition. But it's just an example!
process:
source_is_five:
plugin: evaluate_condition
source: source_value
condition:
plugin: and
conditions:
-
plugin: greater_than
value: 4
-
plugin: greater_than
negate: true
value: 5
-
plugin: callback
callable: is_int3. Set a boolean if the source is large and in charge.
This example demonstrates the iterate property which is only available on logical conditions (and and or).
process:
large_and_in_charge:
plugin: evaluate_condition
source:
- source_size
- source_comportment
condition:
plugin: and
iterate: true
conditions:
-
plugin: equals
value: 'large'
-
plugin: equals
value: 'in charge'Alternatively, we can configure the source directly on each condition. This is a situation where this strategy leads to simpler code.
process:
large_and_in_charge:
plugin: evaluate_condition
condition:
plugin: and
conditions:
-
plugin: equals
value: 'large'
source: source_size
-
plugin: equals
value: 'in charge'
source: source_comportment
Help improve this page
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