Has Element
Evaluates the configured condition on each array element (or on a single element with the specified index) and returns TRUE if at least one element meets the condition.
Available configuration keys:
- condition: The condition plugin to evaluate on each element. Can be either:
- The id of the condition. This is possible if the condition does not require any configuration, such as the 'empty' condition
- An array with 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.
-
index: (optional) If set, the condition will only be evaluated on the array element with this index/key.
-
negate: (optional) Whether to negate the has_element condition. Defaults to FALSE. You can also negate the 'has_element' plugin by using 'not:has_element' 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.
Note that you should never configure source on the condition that is leveraged by has_element. It wouldn't make any sense.
Examples
1. 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. Set a boolean if at least one source date is in the future
process:
has_future_dates:
plugin: evaluate_condition
source: my_source_date_array
condition:
plugin: has_element
condition:
plugin: not:older_than
format: 'U' #whatever my source date format is
value: 'now'3. Determine if an image is missing alt text
Please note that this is intended as an example of setting the index configuration and may not exactly match the structure of all image data.
process:
is_missing_alt_text:
plugin: evaluate_condition
source: my_image_field
condition:
plugin: has_element
index: 'alt'
condition: emptyHelp 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