function field_has_data

7.x field.module field_has_data($field)

Determine whether a field has any data.


$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 drupal/modules/field/tests/field.test
Test field_has_data().
field_ui_field_edit_form in drupal/modules/field_ui/
Form constructor for the field instance settings form.
field_ui_field_settings_form in drupal/modules/field_ui/
Form constructor for the field settings edit page.
field_update_field in drupal/modules/field/
Updates a field.


drupal/modules/field/field.module, line 953
Attach custom data fields to Drupal entities.


function field_has_data($field) {
  $query = new EntityFieldQuery();
  $query = $query->fieldCondition($field)->range(0, 1)->count()
  // Neutralize the 'entity_field_access' query tag added by
  // field_sql_storage_field_storage_query(). The result cannot depend on the
  // access grants of the current user.

  return (bool) $query->execute() || (bool) $query->age(FIELD_LOAD_REVISION)->execute();