1 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


core/modules/field/field.module, line 1234
Attach custom data fields to Backdrop entities.


function field_has_data($field) {
  $query = new EntityFieldQuery();
  $query = $query->fieldCondition($field)
    ->range(0, 1)
    // 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