_taxonomy_clean_field_cache
- Versions
- 7
_taxonomy_clean_field_cache($term)
Helper function that clears field cache when terms are updated or deleted
Code
modules/taxonomy/taxonomy.module, line 1180
<?php
function _taxonomy_clean_field_cache($term) {
$cids = array();
// Determine object types that are not cacheable.
$obj_types = array();
foreach (entity_get_info() as $obj_type => $info) {
if (isset($info['cacheable']) && !$info['cacheable']) {
$obj_types[] = $obj_type;
}
}
// Load info for all taxonomy term fields.
$fields = field_read_fields(array('type' => 'taxonomy_term'));
foreach ($fields as $field_name => $field) {
// Assemble an array of vocabulary IDs that are used in this field.
foreach ($field['settings']['allowed_values'] as $tree) {
$vids[$tree['vid']] = $tree['vid'];
}
// Check this term's vocabulary against those used for the field's options.
if (in_array($term->vid, $vids)) {
$conditions = array(array('tid', $term->tid));
if ($obj_types) {
$conditions[] = array('type', $obj_types, 'NOT IN');
}
$results = field_attach_query($field['id'], $conditions, array('limit' => FIELD_QUERY_NO_LIMIT));
foreach ($results as $obj_type => $objects) {
foreach (array_keys($objects) as $id) {
$cids[] = "field:$obj_type:$id";
}
}
}
}
if ($cids) {
cache_clear_all($cids, 'cache_field');
}
}
?>Login or register to post comments 