function taxonomy_menu_taxonomy in Taxonomy menu 6.2
Same name and namespace in other branches
- 5 taxonomy_menu.module \taxonomy_menu_taxonomy()
- 6 taxonomy_menu.module \taxonomy_menu_taxonomy()
Implementation of hook_taxonomy().
When a user inserts, alters or deletes taxonomy terms, we can keep the related menu synchronised to the changes without rebuilding the entire menu (which would delete all other customisations the user may have done).
File
- ./
taxonomy_menu.module, line 260 - It Generates menu links for all selected taxonomy terms
Code
function taxonomy_menu_taxonomy($op, $type, $args = NULL) {
// if submiting vocab, set new preferences
if ($type == 'vocabulary' && $op == 'delete') {
// delete the menu items
_taxonomy_menu_delete_all($args['vid']);
$menu_name = variable_get('taxonomy_menu_vocab_menu_' . $args['vid'], 0);
menu_cache_clear($menu_name);
}
else {
// only sync if taxonomy_menu is enabled for this vocab and the 'sync'
// option has been checked.
$menu_name = variable_get('taxonomy_menu_vocab_menu_' . $args['vid'], 0);
$sync = variable_get('taxonomy_menu_sync_' . $args['vid'], 0);
if ($type == 'term' && $menu_name && $sync) {
// build arguments
switch ($op) {
case 'insert':
// we have to pull from the args because using a taxonomy function pulls from the cache
$term->name = $args['name'];
$term->description = $args['description'];
$term->parents = $args['parent'];
$term->weight = $args['weight'];
$term->vid = $args['vid'];
$term->tid = $args['tid'];
$item = array(
'term' => $term,
'menu_name' => $menu_name,
);
$message = t('Term %term has been added to taxonomy menu %menu_name.', array(
'%term' => $args['name'],
'%menu_name' => $menu_name,
));
break;
case 'update':
// we have to pull from the args because using a taxonomy function pulls from the cache
$term->name = $args['name'];
$term->description = $args['description'];
$term->parents = $args['parent'];
$term->weight = $args['weight'];
$term->vid = $args['vid'];
$term->tid = $args['tid'];
$item = array(
'term' => $term,
'menu_name' => $menu_name,
'mlid' => _taxonomy_menu_get_mlid($args['tid'], $args['vid']),
);
$message = t('Term %term has been updated in taxonomy menu %menu_name.', array(
'%term' => $args['name'],
'%menu_name' => $menu_name,
));
break;
case 'delete':
$item = array(
'tid' => $args['tid'],
'vid' => $args['vid'],
'menu_name' => $menu_name,
'term' => taxonomy_get_term($args['tid']),
'mlid' => _taxonomy_menu_get_mlid($args['tid'], $args['vid']),
);
$message = t('Term %term has been deleted from taxonomy menu %menu_name.', array(
'%term' => $args['name'],
'%menu_name' => $menu_name,
));
break;
}
// run function
taxonomy_menu_handler($op, $item);
// report status
drupal_set_message($message, 'status');
// rebuild the menu
menu_cache_clear($menu_name);
}
}
}