Utility function: fetch all the field definitions from the database.
Warning: unlike the field_read_fields() API function, this function returns all fields by default, including deleted and inactive fields, unless specified otherwise in the $conditions parameter.
$conditions: An array of conditions to limit the select query to.
$key: The name of the field property the return array is indexed by. Using anything else than 'id' might cause incomplete results if the $conditions do not filter out deleted fields.
An array of fields matching $conditions, keyed by the property specified by the $key parameter.
function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') {
$fields = array();
$query = db_select('field_config', 'fc', array(
'fetch' => PDO::FETCH_ASSOC,
))
->fields('fc');
foreach ($conditions as $column => $value) {
$query
->condition($column, $value);
}
foreach ($query
->execute() 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'];
$fields[$field[$key]] = $field;
}
return $fields;
}