FieldInfo::getFieldMap

public function FieldInfo::getFieldMap

public 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.

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.info.class.inc/function/FieldInfo::getFieldMap/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部