function hook_field_is_empty

You are here

7 field.api.php hook_field_is_empty($item, $field)

Define what constitutes an empty item for a field type.

Parameters

$item: An item that may or may not be empty.

$field: The field to which $item belongs.

Return value

TRUE if $field's type considers $item not to contain any data; FALSE otherwise.

Related topics

7 functions implement hook_field_is_empty()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_field_is_empty in modules/field/tests/field_test.field.inc
Implements hook_field_is_empty().
file_field_is_empty in modules/file/file.field.inc
Implements hook_field_is_empty().
image_field_is_empty in modules/image/image.field.inc
Implements hook_field_is_empty().
list_field_is_empty in modules/field/modules/list/list.module
Implements hook_field_is_empty().
number_field_is_empty in modules/field/modules/number/number.module
Implements hook_field_is_empty().

... See full list

File

modules/field/field.api.php, line 683

Code

function hook_field_is_empty($item, $field) {
  if (empty($item['value']) && (string) $item['value'] !== '0') {
    return TRUE;
  }
  return FALSE;
}

Comments

I think the hook should be

function hook_field_is_empty($item, $field) {
if (empty($item['value']) && $item['value'] !== '0') {
return TRUE;
}
return FALSE;
}

Next time you should file a bug report once you find an error in the documentation or the code.
Here (string) is used to cast the item value to a string before comparing with '0'. This is done because a string '0' is not an empty string, while the integer 0 is in most cases an integer field with no value.

Or more simply :

<?php
function hook_field_is_empty($item, $field) {
    return empty(
$item['value']) && (string) $item['value'] !== '0';
}
?>