You are here

function taxonomy_entity_index_get_taxonomy_field_names in Taxonomy Entity Index 7

Same name and namespace in other branches
  1. 8 taxonomy_entity_index.module \taxonomy_entity_index_get_taxonomy_field_names()

Return all the taxonomy field names for a given entity type and bundle.

3 calls to taxonomy_entity_index_get_taxonomy_field_names()
taxonomy_entity_index_field_attach_update in ./taxonomy_entity_index.module
Implements hook_field_attach_update().
taxonomy_entity_index_reindex_entity_type in ./taxonomy_entity_index.module
Batch callback; re-index all the terms for a given entity type.
taxonomy_entity_index_token_info_alter in ./taxonomy_entity_index.tokens.inc
Implements hook_token_info_alter().

File

./taxonomy_entity_index.module, line 66

Code

function taxonomy_entity_index_get_taxonomy_field_names($type = NULL, $bundle = NULL) {
  $taxonomy_fields =& drupal_static(__FUNCTION__);
  if (!isset($taxonomy_fields)) {
    if ($cache = cache_get('entity-taxonomy-fields', 'cache_field')) {
      $taxonomy_fields = $cache->data;
    }
    else {
      $taxonomy_fields = array();
      $fields = field_info_fields();
      foreach ($fields as $field) {
        if ($field['type'] != 'taxonomy_term_reference') {
          continue;
        }
        foreach ($field['bundles'] as $entity_type => $bundles) {
          foreach ($bundles as $entity_bundle) {
            $taxonomy_fields[$entity_type][$entity_bundle][] = $field['field_name'];
          }
        }
      }
      cache_set('entity-taxonomy-fields', $taxonomy_fields, 'cache_field');
    }
  }
  if (isset($bundle)) {
    return isset($taxonomy_fields[$type][$bundle]) ? $taxonomy_fields[$type][$bundle] : array();
  }
  elseif (isset($type)) {
    return isset($taxonomy_fields[$type]) ? $taxonomy_fields[$type] : array();
  }
  else {
    return $taxonomy_fields;
  }
}