In context_ui_editor_process and context_ui_form_process there are blocks that say:
if ($submit && context_empty($context->conditions[$condition]['values'])) {
unset($context->conditions[$condition]);
}
These will automatically remove any contexts which are "empty". This includes contexts that have their fields set to 0, which could well be a valid value. (in my case I'm writing 'min/max search results' plugins, and I want to support the case of there being no results).
The purpose of this code is presumably to make the 'conditions' list on the edit screen a little prettier by removing any conditions that are no longer used by the context. I think that's actually a bad UI anyway, because it is fairly likely that users will edit the same context multiple times as they try to get it to work properly and may clear all values from a particular condition plugin, but soon after change their mind and add those values back. They shouldn't need to find the condition plugin from the dropdown again - it should be in the list as they were only just using it. If they are sure they don't want it any more then it is easy for them to click the remove link.
If others disagree with my reasoning, then how about changing context_empty so the non-array check is
$empty = $empty && empty($element) && $element !== '0' && $element !== 0;
This will mean the condition will be removed for empty strings and empty arrays, but will remain for zeros.
Comment | File | Size | Author |
---|---|---|---|
#1 | context_empty-1842566-1.patch | 303 bytes | Deciphered |
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedYes, I just hit this issue with a reaction, that reaction being:
'environment_indicator_status' => 0
For my module, this is a valid reaction, however it will get removed as it is deemed as empty.
Maybe instead of checking empty, it should check either for is_null() or !isset().
!isset() patch attached.
Comment #2
ianthomas_ukThat solution works for me
Comment #3
colanCommitted in a19066c.