You are here

public function FieldInfo::getFields in Drupal 7

Returns all active fields, including deleted ones.

Return value

An array of field definitions, keyed by field ID.

1 call to FieldInfo::getFields()
FieldInfo::getInstances in modules/field/field.info.class.inc
Retrieves all active, non-deleted instances definitions.

File

modules/field/field.info.class.inc, line 163

Class

FieldInfo
Provides field and instance definitions for the current runtime environment.

Code

public function getFields() {

  // Read from the "static" cache.
  if ($this->loadedAllFields) {
    return $this->fieldsById;
  }

  // Read from persistent cache.
  if ($cached = cache_get('field_info:fields', 'cache_field')) {
    $this->fieldsById = $cached->data;
  }
  else {

    // Collect and prepare fields.
    foreach (field_read_fields(array(), array(
      'include_deleted' => TRUE,
    )) as $field) {
      $this->fieldsById[$field['id']] = $this
        ->prepareField($field);
    }

    // Store in persistent cache.
    if (lock_acquire('field_info:fields')) {
      cache_set('field_info:fields', $this->fieldsById, 'cache_field');
      lock_release('field_info:fields');
    }
  }

  // Fill the name/ID map.
  foreach ($this->fieldsById as $field) {
    if (!$field['deleted']) {
      $this->fieldIdsByName[$field['field_name']] = $field['id'];
    }
  }
  $this->loadedAllFields = TRUE;
  return $this->fieldsById;
}