function _taxonomy_menu_termapi_helper in Taxonomy menu 8
Same name and namespace in other branches
- 7.2 taxonomy_menu.module \_taxonomy_menu_termapi_helper()
Abstraction of hook_termapi_<op>().
Parameters
$term: The term to process.
$operation: A string of the operation to be performed [update|insert|delete].
3 calls to _taxonomy_menu_termapi_helper()
- taxonomy_menu_taxonomy_term_delete in ./
taxonomy_menu.module - Implements hook_taxonomy_term_delete().
- taxonomy_menu_taxonomy_term_insert in ./
taxonomy_menu.module - Implements hook_taxonomy_term_insert($term).
- taxonomy_menu_taxonomy_term_update in ./
taxonomy_menu.module - Implements hook_taxonomy_term_update().
File
- ./
taxonomy_menu.module, line 445 - Generates menu links for all selected taxonomy terms.
Code
function _taxonomy_menu_termapi_helper($term, $operation) {
// Only sync if taxonomy_menu is enabled for this vocab and the 'sync'
// option has been checked.
$menu_name = taxonomy_menu_variable_get('vocab_menu', $term
->bundle(), 0);
$sync = taxonomy_menu_variable_get('sync', $term
->bundle(), 0);
if ($menu_name && $sync) {
switch ($operation) {
case 'insert':
$text = 'Added term %term to taxonomy menu %menu_name.';
break;
case 'update':
$text = 'Updated term %term in taxonomy menu %menu_name.';
break;
case 'delete':
$text = 'Deleted term %term from taxonomy menu %menu_name.';
break;
}
$message = t($text, array(
'%term' => $term->name->value,
'%menu_name' => $menu_name,
));
if ($operation == 'delete') {
$mlid = _taxonomy_menu_get_mlid($term
->id(), $term
->bundle());
_taxonomy_menu_delete_item($term
->bundle(), $term
->id());
menu_link_delete($mlid);
}
else {
taxonomy_menu_menu_link_save($term, $menu_name);
}
drupal_set_message($message, 'status');
\Drupal::state()
->set('menu_rebuild_needed', TRUE);
}
}