You are here

function _taxonomy_menu_termapi_helper in Taxonomy menu 7.2

Same name and namespace in other branches
  1. 8 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 451
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->vid, 0);
  $sync = taxonomy_menu_variable_get('sync', $term->vid, 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,
      '%menu_name' => $menu_name,
    ));
    if ($operation == 'delete') {
      $mlid = _taxonomy_menu_get_mlid($term->tid, $term->vid);
      _taxonomy_menu_delete_item($term->vid, $term->tid);
      menu_link_delete($mlid);
    }
    else {
      taxonomy_menu_menu_link_save($term, $menu_name);
    }
    drupal_set_message($message, 'status');
    variable_set('menu_rebuild_needed', TRUE);
  }
}