Or Condition

Last updated on
20 November 2022

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 'or' condition should be negated. Defaults to FALSE. You can also negate the 'or' plugin by using 'not:or' 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. Evaluate if a value is less than or equal to zero

This should really be done by using not:greater_than, but it's just an example.

process:
  not_positive:
    plugin: evaluate_condition
    source: source_value
    condition:
      plugin: or
      conditions:
        -
          plugin: less_than
          value: 0
        -
          plugin: equals
          value: 0

2. Evaluate if a source value is 5, or '5', or 'five', or something that clearly should be read as five. 

process:
  some_kind_of_5:
    -
      plugin: callback
      callable: strtolower
      source: my_source_value
    -
      plugin: evaluate_condition
      condition:
        plugin: or
        conditions:
          -
            plugin: equals
            value: 5
          -
            plugin: equals
            value: 'five'

 3. Set a boolean if the source image is missing 'alt' or 'title'.

This example demonstrates the iterate property which is only available on logical conditions (and and or). Assume field_image is a single array with properties like 'alt', 'title', filename', url', etc. This may not entirely match reality, but it's just an example.

process:
  missing_data:
    plugin: evaluate_condition
    source: field_image
    condition:
      plugin: or
      iterate: true
      conditions:
        alt:
          plugin: empty
        title:
          plugin: empty

As an alternative to the iterate configuration, we could specify separate sources for the OR-ed conditions. 

process:
  missing_data:
    plugin: evaluate_condition
    condition:
      plugin: or
      conditions:
        -
          plugin: empty
          source: field_image/alt
        -
          plugin: empty
          source: field_image/title

Help improve this page

Page status: No known problems

You can: