Funny one with an easy workaround, but worth reporting.
Steps to replicate:
1) Create a Boolean field and leave the label values empty.
2) Create a view and try setting a filter with this.
The list appears empty, when it actually contains two empty values:
class views_handler_filter_field_list {
function get_value_options() {
$field = field_info_field($this->definition['field_name']);
$this->value_options = list_allowed_values($field);
// $this->value_options == array(0 => '', 1=> '')
}
}
Workaround is to define two values, which can be 0 & 1 and the array values are populated with this.
The issue itself is a core issue, example fix below, but I am guessing this will never be resolved in D7 :(
function list_allowed_values($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
$allowed_values = &drupal_static(__FUNCTION__, array());
if (!isset($allowed_values[$field['id']])) {
$function = $field['settings']['allowed_values_function'];
// If $cacheable is FALSE, then the allowed values are not statically
// cached. See list_test_dynamic_values_callback() for an example of
// generating dynamic and uncached values.
$cacheable = TRUE;
if (!empty($function) && function_exists($function)) {
$values = $function($field, $instance, $entity_type, $entity, $cacheable);
}
else {
$values = $field['settings']['allowed_values'];
+ if ($field['type'] == 'list_boolean') {
+ foreach ($values as $key => $value) {
+ if (!strlen($value)) {
+ $value = $key;
+ }
+ }
+ }
}
Comments
Comment #1
neRok commentedMarking as duplicate of #1793432: For boolean with empty values, list_allowed_values() should return array('0', '1')
Thanks for posting the code snippet. I will use it to make a patch now, and test it out.
Comment #2
alan d. commentedreopening as neRok closed the core issue that was the duplicate of this one... :/