Returns a map of field names and vocabularies they can reference

function _get_tax_term_fields_map() {
  static $map;
  if (isset($map)) {
    return $map;
  }

  // First, find all taxonomy term fields.
  foreach (field_info_fields() as $field) {
    if ('taxonomy_term_reference' === $field['type']) {
      $all[] = $field;
    }
  }

  // Next, build a map, keyed by the field name.
  foreach ($all as $field) {
    foreach ($field['settings']['allowed_values'] as $vocab_info) {
      foreach ($field['bundles'] as $entity_type => $bundle_names) {
        $map[$field['field_name']]['vocabs'][] = $vocab_info['vocabulary'];
        $map[$field['field_name']]['bundles'][$entity_type] = drupal_map_assoc($bundle_names);
      }
    }
  }

  return $map;
}

Tags: