function better_statistics_get_entity_terms in Better Statistics 7
Fetch all taxonomy term IDs from an entity.
All fields of field type "taxonomy_term_reference" will be included.
Parameters
string $entity_type: The type of entity.
string $bundle: The entity bundle of the given entity.
object $entity: Actual entity object to process.
Return value
array Array of tids.
1 call to better_statistics_get_entity_terms()
- taxonomy_get_statistics_field_value in modules/
taxonomy.statistics.inc - Returns the stats field value for a given field.
File
- modules/
taxonomy.statistics.inc, line 230 - Statistics API functions and hooks for the Taxonomy module.
Code
function better_statistics_get_entity_terms($entity_type, $bundle, $entity) {
// Ensure all functions are loaded.
if (!function_exists('field_info_field_map') || !function_exists('field_get_items')) {
return array();
}
// Use very lightweight field info list to find relevant fields.
$tids = array();
foreach (field_info_field_map() as $field_name => $field_info) {
if ($field_info['type'] != 'taxonomy_term_reference') {
continue;
}
if (array_key_exists($entity_type, $field_info['bundles'])) {
if (in_array($bundle, $field_info['bundles'][$entity_type])) {
if (isset($entity->{$field_name})) {
// Collect terms from fields for return.
$values = field_get_items($entity_type, $entity, $field_name);
foreach ((array) $values as $term_array) {
if (!empty($term_array['tid'])) {
$tids[] = $term_array['tid'];
}
}
}
}
}
}
return $tids;
}