function field_has_data
Determine whether a field has any data.
Parameters
$field: A field structure.
Return value
TRUE if the field has data for any entity; FALSE otherwise.
Related topics
4 calls to field_has_data()
- FieldAttachStorageTestCase::testFieldHasData in modules/
field/ tests/ field.test - Test field_has_data().
- field_ui_field_edit_form in modules/
field_ui/ field_ui.admin.inc - Form constructor for the field instance settings form.
- field_ui_field_settings_form in modules/
field_ui/ field_ui.admin.inc - Form constructor for the field settings edit page.
- field_update_field in modules/
field/ field.crud.inc - Updates a field.
File
-
modules/
field/ field.module, line 953
Code
function field_has_data($field) {
$query = new EntityFieldQuery();
$query = $query->fieldCondition($field)
->range(0, 1)
->count()
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
return (bool) $query->execute() || (bool) $query->age(FIELD_LOAD_REVISION)
->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.