function taxonomy_tools_taxonomy_term_presave in Taxonomy Tools 8
Same name and namespace in other branches
- 7 taxonomy_tools.module \taxonomy_tools_taxonomy_term_presave()
Implements hook_taxonomy_term_presave().
File
- ./
taxonomy_tools.module, line 481 - Drupal hooks and functions to work with taxonomy terms.
Code
function taxonomy_tools_taxonomy_term_presave($term) {
if (arg(4) == 'overview' || arg(3) == 'overview') {
$count = array();
// Take in account that term can have more than one parent.
foreach ($term->parent as $tid) {
$query = db_select('taxonomy_term_hierarchy', 'foo');
$query
->addField('foo', 'tid');
$query
->condition('foo.parent', $tid);
$query
->join('taxonomy_term_data', 'bar', 'foo.tid = bar.tid');
$query
->condition('bar.vid', $term->vid);
$count[] = $query
->countQuery()
->execute()
->fetchField();
}
// Set term weight to siblings count + 1.
// We use the biggest siblings count.
$term->weight = max($count) + 1;
}
}