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::getBundleInstances in drupal/core/modules/field/lib/Drupal/field/FieldInfo.php
Retrieves the instances for a bundle.

File

drupal/core/modules/field/lib/Drupal/field/FieldInfo.php, line 162
Contains \Drupal\field\FieldInfo.

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 = $this->cacheBackend
    ->get('field_info:field_map')) {
    $map = $cached->data;

    // Save in "static" cache.
    $this->fieldMap = $map;
    return $map;
  }
  $map = array();

  // Get active fields.
  foreach (config_get_storage_names_with_prefix('field.field') as $config_id) {
    $field_config = $this->config
      ->get($config_id)
      ->get();
    if ($field_config['active'] && $field_config['storage']['active']) {
      $fields[$field_config['uuid']] = $field_config;
    }
  }

  // Get field instances.
  foreach (config_get_storage_names_with_prefix('field.instance') as $config_id) {
    $instance_config = $this->config
      ->get($config_id)
      ->get();
    $field_uuid = $instance_config['field_uuid'];

    // Filter out instances of inactive fields, and instances on unknown
    // entity types.
    if (isset($fields[$field_uuid])) {
      $field = $fields[$field_uuid];
      $map[$field['id']]['bundles'][$instance_config['entity_type']][] = $instance_config['bundle'];
      $map[$field['id']]['type'] = $field['type'];
    }
  }

  // Save in "static" and persistent caches.
  $this->fieldMap = $map;
  $this->cacheBackend
    ->set('field_info:field_map', $map, CacheBackendInterface::CACHE_PERMANENT, array(
    'field_info' => TRUE,
  ));
  return $map;
}