public function FieldInfo::getFieldMap

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 drupal/core/modules/field/lib/Drupal/field/FieldInfo.php
Prepares a field definition for the current run-time context.

File

drupal/core/modules/field/lib/Drupal/field/FieldInfo.php, line 127

Class

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

Namespace

Drupal\field

Code

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;
}