You are here

function gmap_taxonomy_get_instances in GMap Module 7.2

Same name and namespace in other branches
  1. 7 gmap_taxonomy.module \gmap_taxonomy_get_instances()

Get fields that are using taxonomy_term_reference + gmap taxonomy.

@todo move this to GmapFieldsCRUDi class Helper function to return cached version of fields using taxonomy_term_reference.

Return value

array Associative array keyed with node type and with values as array of field names.

1 call to gmap_taxonomy_get_instances()
gmap_taxonomy_node_update in ./gmap_taxonomy.module
Implements hook_node_update().

File

./gmap_taxonomy.module, line 306
GMap Taxonomy Markers

Code

function gmap_taxonomy_get_instances() {
  $gmap_taxonomy_fields =& drupal_static(__FUNCTION__);

  // TODO: Could do something with the vid,
  // but probably too much overhead to use it here.
  // As field_info_fields() only gives us machine names
  // and gmap_taxonomy_vocabs only gives us vid.
  // $gmap_taxonomy_vocabs = variable_get('gmap_taxonomy_vocabs', array());
  if (!isset($gmap_taxonomy_fields)) {
    if ($cache = cache_get('gmap_taxonomy_fields_data')) {
      $gmap_taxonomy_fields = $cache->data;
    }
    else {
      $gmap_taxonomy_fields = array();

      // Get all field info.
      $fields = field_info_fields();

      // Loop through to get the ones of field type taxonomy_term_reference.
      foreach ($fields as $field) {
        if ($field['type'] == 'taxonomy_term_reference' && isset($field['bundles']['node'])) {
          foreach ($field['bundles']['node'] as $node_type) {
            $gmap_taxonomy_fields[$node_type][] = $field['field_name'];
          }
        }
      }
      cache_set('gmap_taxonomy_fields_data', $gmap_taxonomy_fields, 'cache', CACHE_TEMPORARY);
    }
  }
  return $gmap_taxonomy_fields;
}