Collects a lightweight map of fields across bundles.
An array keyed by field name. Each value is an array with two entries:
public function getFieldMap() {
// Read from the "static" cache.
if ($this->fieldMap !== NULL) {
return $this->fieldMap;
}
// Read from persistent cache.
if ($cached = cache('field')
->get('field_info:field_map')) {
$map = $cached->data;
// Save in "static" cache.
$this->fieldMap = $map;
return $map;
}
$map = array();
$query = db_select('field_config_instance', 'fci');
$query
->join('field_config', 'fc', 'fc.id = fci.field_id');
$query
->fields('fc', array(
'type',
));
$query
->fields('fci', array(
'field_name',
'entity_type',
'bundle',
))
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fci.deleted', 0);
foreach ($query
->execute() 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;
cache('field')
->set('field_info:field_map', $map, CacheBackendInterface::CACHE_PERMANENT, array(
'field_info' => TRUE,
));
return $map;
}