_field_info_collate_fields

Versions
7
_field_info_collate_fields($reset = FALSE)

Collate all information on existing fields and instances.

Parameters

$reset If TRUE, clear the cache. The information will be rebuilt from the database next time it is needed. Defaults to FALSE.

Return value

If $reset is TRUE, nothing. If $reset is FALSE, an array containing the following elements:

  • fields: Array of existing fields, keyed by field name. This entry only lists non-deleted fields. Each field has an additional element, 'bundles', which is an array of all non-deleted instances to which the field is assigned.
  • fields_id: Array of existing fields, keyed by field id. This entry lists both deleted and non-deleted fields. The bundles element is the same as for 'fields'.
  • instances: Array of existing instances, keyed by object type, bundle name and field name. This entry only lists non-deleted instances.

Related topics

▾ 6 functions call _field_info_collate_fields()

field_info_cache_clear in modules/field/field.info.inc
Clear the field info cache without clearing the field data cache.
field_info_field in modules/field/field.info.inc
Return data about an individual field.
field_info_fields in modules/field/field.info.inc
Return all field definitions.
field_info_field_by_id in modules/field/field.info.inc
Return data about an individual field by its id.
field_info_instance in modules/field/field.info.inc
Return an array of instance data for a specific field and bundle.
field_info_instances in modules/field/field.info.inc
Retrieve instances.

Code

modules/field/field.info.inc, line 164

<?php
function _field_info_collate_fields($reset = FALSE) {
  static $info;

  if ($reset) {
    $info = NULL;
    cache_clear_all('field_info_fields', 'cache_field');
    return;
  }

  if (!isset($info)) {
    if ($cached = cache_get('field_info_fields', 'cache_field')) {
      $definitions = $cached->data;
    }
    else {
      $definitions = array(
        'field_ids' => field_read_fields(array(), array('include_deleted' => 1)),
        'instances' => field_read_instances(),
      );
      cache_set('field_info_fields', $definitions, 'cache_field');
    }

    // Populate 'field_ids' with all fields.
    $info['field_ids'] = array();
    foreach ($definitions['field_ids'] as $key => $field) {
      $info['field_ids'][$key] = $definitions['field_ids'][$key] = _field_info_prepare_field($field);
    }

    // Populate 'fields' only with non-deleted fields.
    $info['fields'] = array();
    foreach ($info['field_ids'] as $field) {
      if (!$field['deleted']) {
        $info['fields'][$field['field_name']] = $field;
      }
    }

    // Populate 'instances'. Only non-deleted instances are considered.
    $info['instances'] = array();
    foreach (field_info_bundles() as $obj_type => $bundles) {
      foreach ($bundles as $bundle => $bundle_info) {
        $info['instances'][$obj_type][$bundle] = array();
      }
    }
    foreach ($definitions['instances'] as $instance) {
      $field = $info['fields'][$instance['field_name']];
      $instance = _field_info_prepare_instance($instance, $field);
      $info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']] = $instance;
      // Enrich field definitions with the list of bundles where they have
      // instances. NOTE: Deleted fields in $info['field_ids'] are not
      // enriched because all of their instances are deleted, too, and
      // are thus not in $definitions['instances'].
      $info['fields'][$instance['field_name']]['bundles'][$instance['object_type']][] = $instance['bundle'];
      $info['field_ids'][$instance['field_id']]['bundles'][$instance['object_type']][] = $instance['bundle'];

      // Add storage details.
      $details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field, $instance);
      drupal_alter('field_storage_details', $details, $field, $instance);
      $info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']]['storage_details'] = $details;
    }
  }

  return $info;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.