function field_read_fields

Reads in fields that match an array of conditions.


array $params: An array of conditions to match against. Keys are columns from the 'field_config' table, values are conditions to match. Additionally, conditions on the 'entity_type' and 'bundle' columns from the 'field_config_instance' table are supported (select fields having an instance on a given bundle).

array $include_additional: The default behavior of this function is to not return fields that are inactive or have been deleted. Setting $include_additional['include_inactive'] or $include_additional['include_deleted'] to TRUE will override this behavior.

Return value

An array of fields matching $params. If $include_additional['include_deleted'] is TRUE, the array is keyed by field id, otherwise it is keyed by field name.

Related topics

14 calls to field_read_fields()
FieldBulkDeleteTestCase::testPurgeField in drupal/modules/field/tests/field.test
Verify that fields are preserved and purged correctly as multiple instances are deleted and purged.
FieldBulkDeleteTestCase::testPurgeInstance in drupal/modules/field/tests/field.test
Verify that field data items and instances are purged when an instance is deleted.
FieldCrudTestCase::testReadFields in drupal/modules/field/tests/field.test
Tests reading field definitions.
FieldCrudTestCase::_testActiveHelper in drupal/modules/field/tests/field.test
Helper function for testActive().
FieldInfo::getBundleInstances in drupal/modules/field/
Retrieves the instances for a bundle.

... See full list


drupal/modules/field/, line 340
Field CRUD API, handling field and field instance creation and deletion.


function field_read_fields($params = array(), $include_additional = array()) {
  $query = db_select('field_config', 'fc', array(
    'fetch' => PDO::FETCH_ASSOC,

  // Turn the conditions into a query.
  foreach ($params as $key => $value) {

    // Allow filtering on the 'entity_type' and 'bundle' columns of the
    // field_config_instance table.
    if ($key == 'entity_type' || $key == 'bundle') {
      if (empty($fci_join)) {
        $fci_join = $query
          ->join('field_config_instance', 'fci', ' = fci.field_id');
      $key = 'fci.' . $key;
    else {
      $key = 'fc.' . $key;
      ->condition($key, $value);
  if (!isset($include_additional['include_inactive']) || !$include_additional['include_inactive']) {
      ->condition('', 1)
      ->condition('fc.storage_active', 1);
  $include_deleted = isset($include_additional['include_deleted']) && $include_additional['include_deleted'];
  if (!$include_deleted) {
      ->condition('fc.deleted', 0);
  $fields = array();
  $results = $query
  foreach ($results as $record) {
    $field = unserialize($record['data']);
    $field['id'] = $record['id'];
    $field['field_name'] = $record['field_name'];
    $field['type'] = $record['type'];
    $field['module'] = $record['module'];
    $field['active'] = $record['active'];
    $field['storage']['type'] = $record['storage_type'];
    $field['storage']['module'] = $record['storage_module'];
    $field['storage']['active'] = $record['storage_active'];
    $field['locked'] = $record['locked'];
    $field['cardinality'] = $record['cardinality'];
    $field['translatable'] = $record['translatable'];
    $field['deleted'] = $record['deleted'];
    module_invoke_all('field_read_field', $field);

    // Populate storage information.
    $schema = (array) module_invoke($field['module'], 'field_schema', $field);
    $schema += array(
      'columns' => array(),
      'indexes' => array(),
    $field['columns'] = $schema['columns'];
    $field_name = $field['field_name'];
    if ($include_deleted) {
      $field_name = $field['id'];
    $fields[$field_name] = $field;
  return $fields;