Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291890

list_field_is_empty() always returns FALSE for list_boolean fields

$
0
0

Currently, list_field_is_empty() uses the following conditional to test whether a field is empty:

<?php
if (empty($item['value']) && (string) $item['value'] !== '0')
?>

In other words, if the empty() function returns TRUE and the string value of the field is also not zero, then it is empty. This seems fine for most list fields, but causes big problems when writing code for Boolean fields. One would reasonably expect this function to return TRUE for a value of 0, which in the context of a single on/off checkbox, is empty. However, this function will always return FALSE for Booleans, whether you pass it 0 or 1.

One place where this causes problems is with field collections. Suppose you have a field collection that consists of two required fields and one optional Boolean (a single on/off checkbox). The field collection module uses the emptiness of the collection to decide whether to enforce validation of required fields. But because list_field_is_empty() always returns FALSE for single on/off checkboxes, the collection can never be considered empty.

The attached patch adds a check to see if we're dealing with a list_boolean field and, if so, considers 0 to be empty.

AttachmentSizeStatusTest resultOperations
field-return_true_for_booleans.patch616 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 40,345 pass(es), 2 fail(s), and 1 exception(s).View details | Re-test

Viewing all articles
Browse latest Browse all 291890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>