public function FieldInfo::getFieldMap in Drupal 7
Collects a lightweight map of fields across bundles.
Return value
An array keyed by field name. Each value is an array with two entries:
- type: The field type.
- bundles: The bundles in which the field appears, as an array with entity types as keys and the array of bundle names as values.
1 call to FieldInfo::getFieldMap()
- FieldInfo::prepareField in modules/
field/ field.info.class.inc - Prepares a field definition for the current run-time context.
File
- modules/
field/ field.info.class.inc, line 123
Class
- FieldInfo
- Provides field and instance definitions for the current runtime environment.
Code
public function getFieldMap() {
// Read from the "static" cache.
if ($this->fieldMap !== NULL) {
return $this->fieldMap;
}
// Read from persistent cache.
if ($cached = cache_get('field_info:field_map', 'cache_field')) {
$map = $cached->data;
// Save in "static" cache.
$this->fieldMap = $map;
return $map;
}
$map = array();
$query = db_query('SELECT fc.type, fci.field_name, fci.entity_type, fci.bundle FROM {field_config_instance} fci INNER JOIN {field_config} fc ON fc.id = fci.field_id WHERE fc.active = 1 AND fc.storage_active = 1 AND fc.deleted = 0 AND fci.deleted = 0');
foreach ($query as $row) {
$map[$row->field_name]['bundles'][$row->entity_type][] = $row->bundle;
$map[$row->field_name]['type'] = $row->type;
}
// Save in "static" and persistent caches.
$this->fieldMap = $map;
if (lock_acquire('field_info:field_map')) {
cache_set('field_info:field_map', $map, 'cache_field');
lock_release('field_info:field_map');
}
return $map;
}