function field_has_data

field_has_data($field)

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

File

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

Code

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.
    ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.module/function/field_has_data/7.x